0

I'm running into the issue of having to differentiate between two error cases which both throw a Java BadrequestException, which shows up as having a 400 error code. I've extended BadrequestException to create a CustomException, but this Exception also throws a 400. Is there a way to have a custom exception throw an "unassigned" error code, like 469, for example? And how would I go about doing that?

6
  • 1
    We have no idea of which framework you're using. There are many, many of them. So, find out what you're using, then read the documentation of the framework. It probably contains the information. Commented Mar 28, 2018 at 18:51
  • Framework as in angularjs? Commented Mar 28, 2018 at 18:54
  • No. AngularJS is a JavaScript framework, used at client-side. You're using a Java framework, at server-side. Commented Mar 28, 2018 at 18:55
  • Ohh sorry. We're using Maven. Commented Mar 28, 2018 at 18:58
  • Yeah, but that is completely irrelevant. Maven is a build tool. Not a Java web framework. If nobody in your team is able to even name the framework you chose to implement your app, how can you even work? Do you guys never read any documentation? Commented Mar 28, 2018 at 19:11

1 Answer 1

1

Assuming you are using JAX-RS you can create a new exception with a custom HTTP status code like so:

public class CustomException extends WebApplicationException {
    private static final long serialVersionUID = 1L;

    public CustomException() {
        super(469);
    }
}
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.