use of com.kickstarter.services.apiresponses.ErrorEnvelope in project android-oss by kickstarter.
the class ApiExceptionFactory method invalidLoginException.
@NonNull
public static ApiException invalidLoginException() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("Invalid login.")).httpCode(401).ksrCode(ErrorEnvelope.INVALID_XAUTH_LOGIN).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
use of com.kickstarter.services.apiresponses.ErrorEnvelope in project android-oss by kickstarter.
the class ApiErrorOperator method call.
@Override
public Subscriber<? super Response<T>> call(@NonNull final Subscriber<? super T> subscriber) {
final Gson gson = this.gson;
return new Subscriber<retrofit2.Response<T>>() {
@Override
public void onCompleted() {
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
@Override
public void onError(@NonNull final Throwable e) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(e);
}
}
@Override
public void onNext(@NonNull final retrofit2.Response<T> response) {
if (subscriber.isUnsubscribed()) {
return;
}
if (!response.isSuccessful()) {
try {
final ErrorEnvelope envelope = gson.fromJson(response.errorBody().string(), ErrorEnvelope.class);
subscriber.onError(new ApiException(envelope, response));
} catch (@NonNull final IOException e) {
subscriber.onError(new ResponseException(response));
}
} else {
subscriber.onNext(response.body());
subscriber.onCompleted();
}
}
};
}
use of com.kickstarter.services.apiresponses.ErrorEnvelope in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaRequired.
@NonNull
public static ApiException tfaRequired() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_REQUIRED).httpCode(403).errorMessages(Collections.singletonList("Two-factor authentication required.")).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
use of com.kickstarter.services.apiresponses.ErrorEnvelope in project android-oss by kickstarter.
the class ApiExceptionFactory method badRequestException.
@NonNull
public static ApiException badRequestException() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("bad request")).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, "");
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(400, body);
return new ApiException(envelope, response);
}
use of com.kickstarter.services.apiresponses.ErrorEnvelope in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaFailed.
@NonNull
public static ApiException tfaFailed() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_FAILED).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
Aggregations