Mike

REST API Plugin not returning the right HTTP Status

Discussion created by Mike on Aug 20, 2016
Latest reply on Nov 11, 2016 by Redeyes

When I execute a GET request for a room that doesn't exist, I get an HTTP 500 (Internal Server Error) back instead of HTTP 404 (Not Found), which would be the correct return code for REST.

 

My Request:

GET http://localhost:9090/plugins/restapi/v1/chatrooms/doesnt.exist/ HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: AUTHCODE
Host: localhost:9090
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

 

The Response:

HTTP/1.1 500 Internal Server Error
Date: Sat, 20 Aug 2016 09:45:10 GMT
Set-Cookie: JSESSIONID=ino92lblptxfkdxw6at7srmv;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-Frame-Options: deny Content-Length: 0

 

The Server Log is pretty clear:

2016.08.20 11:45:10 ERROR [Jetty-QTP-AdminConsole-63]: org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - RoomNotFoundException: Could not find the chat room with ressource doesnt.exist

 

I didn't test it for other entities, but 404 should always be returned for cases where the requested entity isn't found. HTTP 500 Should really only be returned in case an unexpected Exception occurs.

Outcomes