com.gocardless.errors.GoCardlessErrorMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gocardless-pro Show documentation
Show all versions of gocardless-pro Show documentation
Client library for accessing the GoCardless Pro API
package com.gocardless.errors;
/**
* Provides a mapping between API error responses and exceptions. Users of this library will not
* need to use this class.
*/
public class GoCardlessErrorMapper {
/**
* Maps an error response to an exception.
*
* @param error the error response to map
*/
public static GoCardlessApiException toException(ApiErrorResponse error) {
switch (error.getCode()) {
case 401:
return new AuthenticationException(error);
case 403:
return new PermissionException(error);
case 429:
return new RateLimitException(error);
}
switch (error.getType()) {
case GOCARDLESS:
return new GoCardlessInternalException(error);
case INVALID_API_USAGE:
return new InvalidApiUsageException(error);
case INVALID_STATE:
return new InvalidStateException(error);
case VALIDATION_FAILED:
return new ValidationFailedException(error);
}
throw new IllegalStateException("Unknown error type: " + error.getType());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy