Hi @theirman,
That certainly is one way of doing it! There are multiple different ways to approach this, so I will share a few.
Method 1
You could create your own error pages and then using the web.xml
deployment descriptor within your application, redirect exceptions to the error page you would like.
With Jersey 2, you can map error codes or exception types to error pages by selecting one of the following:
<error-page>
<error-code>403</error-code>
<location>/path/to/errorpage</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/path/to/errorpage</location>
</error-page>
Method 2
Jersey also has an Exception Mapper which would allow you to have a custom error page in a more similar manner to the way you have explained above. This method also doesn’t require you to make an html or jsp error page, unlike the other two methods, which you may prefer.
There is an excellent guide for this on howtodoinjava which I would recommend you read/follow if you wish to use this method as it contains a fully working example which would be too big to include here! That page can be found here Jersey exception handling - Jersey ExceptionMapper Example
Method 3
For a global configuration, you would add a system property named send-error_X
(where X is a number, e.g. send-error_1) for every error page you want to override.
The value of the property specifies the error code, path to the html page relative to the ${com.sun.aas.instanceRoot} variable, and a reason for the error (e.g. Resource not found).
If you specify more custom error pages (for different error codes), you would choose a different number in the system property name, e.g. send-error_1, send-error_2, etc.
An example would be:
send-error_1=code=404 path=${com.sun.aas.instanceRoot}/docroot/404.html reason=Resource_not_found
send-error_1=code=403 path=${com.sun.aas.instanceRoot}/docroot/404.html reason=Forbidden
Additional documentation for this method can be found here: Virtual Servers :: Payara Community Documentation
That’s quite a lot of information but hopefully it allows you to pick the method of providing a custom error page you like best!
Thanks,
James