public class ServiceError extends BaseServiceObject
BaseServiceObject implementation that represents an error occurred during service execution.
Service error may be defined as error response send by the server where in such case the error/response
code may be obtained via getErrorCode() along with the error body via getErrorBody()
respectively. Or it may be defined as a failure that has caused the associated service and request
to fail. In such case isFailure() will return true and the occurred failure may
be obtained via getFailure().NO_REQUEST, NO_SERVICE| Constructor and Description |
|---|
ServiceError(int errorCode,
ResponseBody errorBody)
Creates a new instance of ServiceError with the specified errorCode and errorBody
received from the server as error response for the associated service and request.
|
ServiceError(ServiceError other)
Creates a new instance of ServiceError with data of the given one.
|
ServiceError(Throwable failure)
Creates a new instance of ServiceError with the specified failure.
|
| Modifier and Type | Method and Description |
|---|---|
ResponseBody |
getErrorBody()
Returns the error body of the response send by the server as result to call to the associated
service and request.
|
<T> T |
getErrorBodyAs(Class<T> classOfT)
Returns the error body of this service error as the desired type.
|
int |
getErrorCode()
Returns the error code of the response send by the server as result to call to the associated
service and request.
|
Throwable |
getFailure()
Returns the failure that has caused the associated service and request to fail.
|
boolean |
isError()
Checks whether this service error represents an error response that has been received from
the server for the associated service and request.
|
boolean |
isFailure()
Checks whether this service error represents a failure that has caused the associated service
and request to fail during its execution.
|
void |
setErrorBodyConverter(<any> converter)
Sets a converter that should be used to covert error body of this service error to the desired
object when
getErrorBodyAs(Class) is called. |
String |
toString() |
getRequestId, getServiceId, setRequestId, setServiceIdpublic ServiceError(int errorCode,
@NonNull
ResponseBody errorBody)
errorCode - The error/response code returned by the server.errorBody - The body of error response returned by the server.getErrorCode(),
getErrorBody()public ServiceError(@NonNull Throwable failure)
failure - The failure that has caused the associated service and request to fail.isFailure(),
getFailure()public ServiceError(@NonNull ServiceError other)
Note, that this is same as creating shallow copy of the error object.
other - The other service error of which data to copy to the new one.public final boolean isError()
True if this error is an error response send by the server where the response
code may be obtained via getErrorCode() and the error body via getErrorBody()
respectively.isFailure()public int getErrorCode()
NullPointerException - If this error is not an error response but a failure.getErrorBody()@NonNull public ResponseBody getErrorBody()
NullPointerException - If this error is not an error response but a failure.getErrorCode()public void setErrorBodyConverter(@Nullable <any> converter)
getErrorBodyAs(Class) is called.converter - The desired converter to be used for conversion. May be null to clear
the current one.@Nullable public <T> T getErrorBodyAs(@NonNull Class<T> classOfT)
T - The desired type as which to return error body or null if conversion fails.classOfT - Class ot the type to which to convert the error body.NullPointerException - If this error is not an error response but a failure.NullPointerException - If no converter has been specified.public final boolean isFailure()
True if this error is a failure that may be obtained via getFailure(),
false if it is an error response.isError()@NonNull public Throwable getFailure()
NullPointerException - If this error is not a failure but an error response.