Try OpenEdge Now
skip to main content
Configuration
Configuring third-party Web applications : OpenEdge Management REST API framework : Exception handling
 

Exception handling

The REST API framework expects the REST handler methods to throw exceptions of RequestException type. The RequestException requires an HTTP response code and a description text that is used to return an error to the client. However, an inner exception may also be passed to the constructor.
If a RequestException is thrown from a REST handler method, the framework considers it as a known exception and returns a JSON formatted response body with error text to the client. In some cases, the REST handler method might throw any subclass of RequestException.
The framework considers the RequestException as a normal termination of the REST handler method and does not log the exception. On other hand, an exception that does not extend RequestException is considered as an application error and recorded in the fathom error log file. The client then receives a response body with error text HTTP 500 Internal Server Error from the exception.
An example of RequestException:
@RequestMapping(path = "/get", method = RequestMethod.GET)
public Object getSample(@QueryParam("id") String idFromQuery) {
    if ("0".equals(id)){
        throw new RequestException("Invalid id", HttpServletResponse.SC_BAD_REQUEST);
    }
    ...
}
The corresponding response:
{
    error: {
        stack: [ ],
        number: "403",
        text: "Invalid id",
        source: "OpenEdge Management"
    }
}