clean-architecture-delivery-example icon indicating copy to clipboard operation
clean-architecture-delivery-example copied to clipboard

making controllerAdvice answer more clear

Open murilorrr opened this issue 3 years ago • 0 comments

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);
    }

murilorrr avatar Jun 06 '22 10:06 murilorrr