#how to handle NPE and PSQLException in java spring?

4 messages · Page 1 of 1 (latest)

manic hound
#

hi guys. i was wondering how to handle NPE and PSQLException. can i just add two methods to my RestResponseEntityExceptionHandler? so far i have these methods:

 @ExceptionHandler(value={NoEarlierPaymentException.class})
    protected ResponseEntity<Object> handleNoEarlierPaymentException(NoEarlierPaymentException noEarlierPaymentException, WebRequest webRequest) {
        ErrorResponseDTO[] errorResponseDTOS = {new ErrorResponseDTO(13003, "No earlier payment")};
        return handleExceptionInternal(noEarlierPaymentException, errorResponseDTOS,new HttpHeaders(), HttpStatus.BAD_REQUEST, webRequest);
    }

    @ExceptionHandler(value={DuplicateRequestException.class})
    protected ResponseEntity<Object> handleDuplicateRequestException(DuplicateRequestException duplicateRequestException, WebRequest webRequest) {
        ErrorResponseDTO[] errorResponseDTOS = {new ErrorResponseDTO(13004, "Duplicate request")};
        return handleExceptionInternal(duplicateRequestException, errorResponseDTOS,new HttpHeaders(), HttpStatus.BAD_REQUEST, webRequest);
    }

so i was thinking about handling these exceptions my own way. any help? thx

covert helmBOT
#

This post has been reserved for your question.

Hey @manic hound! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

hollow kindle
#

Prevent them instead of handling?