Created
March 6, 2022 19:22
-
-
Save evrentan/2197cbe6863a2673a763d201782d87b4 to your computer and use it in GitHub Desktop.
Demonstrate Resource Bundle Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* To handle general Exception cases for returning Internal Server Error status | |
* | |
* @param exception Exception | |
* @param request Web Request | |
* @return ResponseEntity<CustomRestError> | |
* | |
* @author <a href="https://github.com/ybqdren">Zhao Wen</a>, <a href="https://github.com/evrentan">Evren Tan</a> | |
* @since 1.0.0 | |
*/ | |
@ExceptionHandler(value = {Exception.class}) | |
public ResponseEntity<CustomRestError> processException(final Exception exception, final HttpServletRequest request) { | |
final String locale = CommonUtility.getHeaderValue("locale"); | |
return responseEntity(CustomRestError.builder() | |
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) | |
.message(MessageUtilityServiceImpl.getMessage("customException.internalServerError.message", Objects.nonNull(locale) ? new Locale(locale) : null, RETRY_AFTER_MINUTES)) | |
.build()); | |
} | |
/** | |
* To handle general Method Not Allowed exception cases for returning Method Not Allowed status | |
* | |
* @param exception Exception | |
* @param request Web Request | |
* @return ResponseEntity<CustomRestError> | |
* | |
* @author <a href="https://github.com/evrentan">Evren Tan</a> | |
* @since 1.0.0 | |
*/ | |
@ExceptionHandler(value = {MethodNotAllowedException.class, HttpClientErrorException.MethodNotAllowed.class}) | |
public ResponseEntity<CustomRestError> processMethodNotAllowedException(final Exception exception, final HttpServletRequest request) { | |
final String locale = CommonUtility.getHeaderValue("locale"); | |
return responseEntity(CustomRestError.builder() | |
.status(HttpStatus.METHOD_NOT_ALLOWED.value()) | |
.message(MessageUtilityServiceImpl.getMessage("customException.methodNotAllowedException.message", Objects.nonNull(locale) ? new Locale(locale) : null)) | |
.build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment