Search in sources :

Example 1 with ApiException

use of com.kickstarter.services.ApiException 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);
}
Also used : ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(android.support.annotation.NonNull)

Example 2 with ApiException

use of com.kickstarter.services.ApiException 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);
}
Also used : ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Gson(com.google.gson.Gson) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(android.support.annotation.NonNull)

Example 3 with ApiException

use of com.kickstarter.services.ApiException 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);
}
Also used : ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Gson(com.google.gson.Gson) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(android.support.annotation.NonNull)

Example 4 with ApiException

use of com.kickstarter.services.ApiException in project android-oss by kickstarter.

the class ApiExceptionFactory method apiError.

@NonNull
public static ApiException apiError(@NonNull final ErrorEnvelope errorEnvelope) {
    final ResponseBody body = ResponseBody.create(null, new Gson().toJson(errorEnvelope));
    final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(errorEnvelope.httpCode(), body);
    return new ApiException(errorEnvelope, response);
}
Also used : Gson(com.google.gson.Gson) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(android.support.annotation.NonNull)

Example 5 with ApiException

use of com.kickstarter.services.ApiException 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);
}
Also used : ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Gson(com.google.gson.Gson) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(androidx.annotation.NonNull)

Aggregations

ApiException (com.kickstarter.services.ApiException)12 ErrorEnvelope (com.kickstarter.services.apiresponses.ErrorEnvelope)10 ResponseBody (okhttp3.ResponseBody)10 Observable (rx.Observable)10 Gson (com.google.gson.Gson)9 NonNull (androidx.annotation.NonNull)7 NonNull (android.support.annotation.NonNull)5 Intent (android.content.Intent)1 Environment (com.kickstarter.libs.Environment)1 MockApiClient (com.kickstarter.mock.services.MockApiClient)1 ResponseException (com.kickstarter.services.ResponseException)1 EmailVerificationEnvelope (com.kickstarter.services.apiresponses.EmailVerificationEnvelope)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 Response (retrofit2.Response)1 Subscriber (rx.Subscriber)1