ATG REST API - How to send different HTTP status code rather than 500

533 Views Asked by At

I am exposing a REST service in which i'm trying to return different HTTP status codes based on the type of error.

Unfortunately the only error status that I managed to send is 500.

I tried the following but it doesn't seem to work.

throw new RestException(e.getMessage(), ServletUtil.getCurrentResponse().getResponse(), 404);

Any ideas?

Thank you in advance.

1

There are 1 best solutions below

0
On

For ATG 11.3 you have different types of RESTful web services:

JAX-RS

If you are using the JAX-RS web services then follow the instructions here

In addition the API Documentation states the following:

Note that all RestExceptions require that a servlet response status code be supplied in order to appropriately set the status on the response object. The error code must be an http status code from the HttpServletResponse object

Also note, there are two RestException classes one is atg.rest.RestException and the other is atg.service.jaxrs.RestException so make sure that you have imported the right one.

REST MVC

If you are using REST MVC (which I am guessing your are) then follow the instructions here.