1

I have this exception handler which works just fine:

@ExceptionHandler(DataNotExistException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Data not exist")
public void handleDataNotExistException() {

}

I need to put this exception handler to the exception will not be shown in the browser. Although it works, it shows the "generic" Jetty Browser error codes. I need to have a JSON-type response type.

I tried returning a Class-type error but the exception shows in the browser. I am thinking of using a Map.

1
  • I tried returning a Map but it did not worked Commented Aug 3, 2012 at 11:09

1 Answer 1

1

If your request contains the header Accept=application/json then annotate your method with @ResponseBody and return the object that will be transformed to json. Remove the reason from @ResponseStatus.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.