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 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 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);
}
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 DiscoveryViewModelTest method testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showErrorMessage.
@Test
public void testShowSnackBar_whenIntentFromDeepLinkSuccessResponse_showErrorMessage() {
final String url = "https://*.kickstarter.com/profile/verify_email";
final Intent intentWithUrl = new Intent().setData(Uri.parse(url));
final ErrorEnvelope errorEnvelope = ErrorEnvelope.builder().httpCode(403).errorMessages(Collections.singletonList("expired")).build();
final ApiException apiException = ApiExceptionFactory.apiError(errorEnvelope);
final MockApiClient mockApiClient = new MockApiClient() {
@NonNull
@Override
public Observable<EmailVerificationEnvelope> verifyEmail(@NonNull final String token) {
return Observable.error(apiException);
}
};
final Environment mockedClientEnvironment = environment().toBuilder().apiClient(mockApiClient).build();
this.vm = new DiscoveryViewModel.ViewModel(mockedClientEnvironment);
this.vm.getOutputs().showSuccessMessage().subscribe(this.showSuccessMessage);
this.vm.getOutputs().showErrorMessage().subscribe(this.showErrorMessage);
this.vm.intent(intentWithUrl);
this.showSuccessMessage.assertNoValues();
this.showErrorMessage.assertValue("expired");
}
Aggregations