Exception Handling

Generally, your REST resources should catch and handle all exceptions, passing messages back to the client-side so it can handle it gracefully .

@GET
public JSONObject getSomething(@QueryParam("foo") String foo){
JSONObject result = new JSONObject();
try {
somethingDangerous();
result.put("success",true);
} catch (Exception e){
result.put("success", false);
result.put("message","Something bad happened. Try again later");
}
return result;
}



Any exceptions thrown by the REST layer will be captured and logged. The user will be presented with a message like the one below which identifies the error by a unique id:
images/download/attachments/144835359/weberrors-version-1-modificationdate-1645045008000-api-v2.png

The exception is logged in a special file in the SharedFileSystem/weberrors directory. The file name contains the server id, the error id, and the user id. The contents of the file provide more information about the error including user context, the URL, the browser user agent string, all of the parameters of the request, and the full stacktrace of the exception.