1

I have the following method:

    @ExceptionHandler(InvalidPriceUpdateException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public String handleInvalidPriceUpdateException(InvalidPriceUpdateException e) throws JsonProcessingException {
        return objectMapper.writeValueAsString(new HttpErrorDTO(e.getMessage()));
    }

I see(in debug) that it invokes but in browser I see 500 error(instead of HttpStatus.BAD_REQUEST). and content of http response contains exception info(instead of HttpErrorDTO structure).

What wrong in my code?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

1

It's because you are returning a String, where you should really be building the entire ResponseEntity. Have a read here on what that means and how to build one for example.

Community
  • 1
  • 1
Eugene
  • 117,005
  • 15
  • 201
  • 306