making controllerAdvice answer more clear
murilorrr opened this issue · 0 comments
murilorrr commented
Thinking about
new ApiResponse(false, ex.getMessage()), HttpStatus.NOT_FOUND
Whats meaning false in ApiResponse constructor?
For fix this we can implements builder design pattern.
In class APIresponse add methods:
public void setSuccess(boolean bool)
public boolean getSuccess()
For the @controllerAdvice we make:
@ExceptionHandler(value = {DomainException.class})
ResponseEntity<ApiResponse> handleDomainException(DomainException ex) {
ApiReponse response = new ApiResponse(ex.getMessage())
.setSuccess(false)
return new ResponseEntity<>(reponse, HttpStatus.NOT_FOUND);
}