Skip to content

Instantly share code, notes, and snippets.

@evrentan
Created March 6, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evrentan/2197cbe6863a2673a763d201782d87b4 to your computer and use it in GitHub Desktop.
Save evrentan/2197cbe6863a2673a763d201782d87b4 to your computer and use it in GitHub Desktop.
Demonstrate Resource Bundle Usage
/**
* 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