コード例 #1
0
 @ExceptionHandler(Exception.class)
 public ResponseEntity<ErrorVo> handleError(HttpServletRequest request, Exception exception) {
   ErrorVo error = new ErrorVo();
   ErrorMessageDTO errorDto = new ErrorMessageDTO();
   logger.error(
       MessageFormat.format(
           O_REQUEST_0_PROPAGOU_A_EXCECAO_1,
           request.getRequestURL().toString(),
           exception.getMessage()),
       exception);
   if (exception instanceof BussinessException) {
     errorDto.message = exception.getMessage();
     errorDto.category = "Business";
     error.errors = new ErrorMessageDTO[] {errorDto};
     return new ResponseEntity<ErrorVo>(error, HttpStatus.SEE_OTHER);
   } else {
     errorDto.message = ERRO_NO_SERVIDOR;
     errorDto.category = "Server";
     error.errors = new ErrorMessageDTO[] {errorDto};
     return new ResponseEntity<ErrorVo>(error, HttpStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #2
0
 @ExceptionHandler(rbprojects.dynamicform.service.ValidationException.class)
 public ResponseEntity<ErrorVo> handleValidateError(
     HttpServletRequest request, ValidationException exception) {
   ErrorVo error = new ErrorVo();
   error.errors = exception.getErrors();
   logger.error(
       MessageFormat.format(
           O_REQUEST_0_PROPAGOU_A_EXCECAO_1,
           request.getRequestURL().toString(),
           exception.getMessage()),
       exception);
   return new ResponseEntity<ErrorVo>(error, HttpStatus.PRECONDITION_FAILED);
 }