Class ErrorExceptionConverter
java.lang.Object
com.totvs.tjf.api.response.error.converter.ErrorExceptionConverter
- Direct Known Subclasses:
ErrorAccessDeniedExceptionConverter,ErrorConstraintViolationExceptionConverter,ErrorHttpClientPermissionErrorExceptionConverter
- Author:
- Thiago A. de Souza Weber
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classError representation withHttpStatusandApiErrorResponse. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConverts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponse.convertAsError(com.totvs.tjf.api.context.stereotype.ApiError error, Exception exception) Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith: HttpStatus:ApiError.status(); ApiErrorMessage: Code:ApiError.value(); Message: a localized and interpolated message for the given code; Detailed message: a localized an interpolated detailment message for the given code.convertAsError(ApiValidated error, Exception exception) Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith: HttpStatus:ApiValidated.status(); ApiErrorMessage: Code:ApiValidated.value(); Message: a localized and interpolated message for the given code; Detailed message: a localized an interpolated detailment message for the given code.convertAsGeneric(Exception exception) Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith: HttpStatus:INTERNAL_SERVER_ERROR; ApiErrorMessage: Code:exception.getClass().getSimpleName(); Message:exception.getLocalizedMessage(); and Detailed message:exception.getCause().getLocalizedMessage(), if a cause exist.
-
Field Details
-
EXCEPTION_NULL_ERROR_MESSAGE
- See Also:
-
API_ERROR_NULL_ERROR_MESSAGE
- See Also:
-
-
Constructor Details
-
ErrorExceptionConverter
public ErrorExceptionConverter(com.totvs.tjf.core.i18n.I18nService i18nService)
-
-
Method Details
-
convert
Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponse.
When annotated withApiErrortheExceptionis mapped as a response error. Otherwise, theExceptionis mapped as a generic response error.- Parameters:
exception- generic exception to be converted- Returns:
- instance of
ErrorExceptionConverter.ExceptionErrorMap - Throws:
NullPointerException- in case the given exception be null- See Also:
-
convertAsGeneric
Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith:- HttpStatus:
INTERNAL_SERVER_ERROR; - ApiErrorMessage:
- Code:
exception.getClass().getSimpleName(); - Message:
exception.getLocalizedMessage(); and - Detailed message:
exception.getCause().getLocalizedMessage(), if a cause exist.
- Code:
- Parameters:
exception- generic exception to be converted- Returns:
- instance of
ErrorExceptionConverter.ExceptionErrorMap - Throws:
NullPointerException- in case the given exception be null
- HttpStatus:
-
convertAsError
public ErrorExceptionConverter.ExceptionErrorMap convertAsError(ApiValidated error, Exception exception) Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith:- HttpStatus:
ApiValidated.status(); - ApiErrorMessage:
- Code:
ApiValidated.value(); - Message: a localized and interpolated message for the given code;
- Detailed message: a localized an interpolated detailment message for the given code. and
- Detail Title: a localized and interpolated detail title for the given code;
- Code:
ApiValidateddoes not have any specified value forcode, the converter, following convention, will use theExceptionsimple name as thecode.- Parameters:
error- api error stereotype.exception- generic exception to be converted- Returns:
- instance of
ErrorExceptionConverter.ExceptionErrorMap - Throws:
IllegalArgumentException- in case the given error or exception be null
- HttpStatus:
-
convertAsError
public ErrorExceptionConverter.ExceptionErrorMap convertAsError(com.totvs.tjf.api.context.stereotype.ApiError error, Exception exception) Converts the givenExceptionto anErrorExceptionConverter.ExceptionErrorMapcontaining theHttpStatusand theApiErrorResponsewith:- HttpStatus:
ApiError.status(); - ApiErrorMessage:
- Code:
ApiError.value(); - Message: a localized and interpolated message for the given code;
- Detailed message: a localized an interpolated detailment message for the given code. and
- Detail Title: a localized and interpolated detail title for the given code;
- Code:
ApiErrordoes not have any specified value forcode, the converter, following convention, will use theExceptionsimple name as thecode.- Parameters:
error- api error stereotype.exception- generic exception to be converted- Returns:
- instance of
ErrorExceptionConverter.ExceptionErrorMap - Throws:
IllegalArgumentException- in case the given error or exception be null
- HttpStatus:
-