The ReST API code throws exceptions that turns into HTTP 500 for things that should be HTTP 400 (Bad Request)

Description

An HTTP 500 should be returned by the web server when a major problem has found while processing a request.

If the request handler found an invalid argument, a null argument, etc., it should return a proper HTTP response instead of HTTP 500.

There are several places on the ReST API on which an IllegalArgumentException is thrown. This is not correct and should be fixed.

Acceptance / Success Criteria

None

Lucidchart Diagrams

Activity

Show:

Alejandro Galue April 2, 2016 at 9:02 AM

Yes. As a general rule, do not ask if you can delete a branch that was merged. If it was merged there is no need to keep it. So, go ahead and delete it.

Ronny Trommer April 1, 2016 at 8:12 PM

seems to be fixed, can we delete the associated branch? https://github.com/OpenNMS/opennms/tree/jira/NMS-7981

Alejandro Galue November 14, 2015 at 7:17 PM

The issue branch was merged into release-17.0.0 on revision f6c5df7a9678711f5dd2dfc70291a7c0224ec49c

Alejandro Galue November 12, 2015 at 4:08 PM
Edited

The way to fix this problem is by either throwing a properly built javax.ws.rs.WebApplicationException, or return javax.ws.rs.core.Response.

The class org.opennms.web.rest.v1.OnmsRestService contains a method called getException which build a WebApplicationException with a message and a custom Status Code. This is used on several end points, but not all of them.

The idea is to normalize the ReST API to catch any exception and wrap it properly using the getException method mentioned above.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Priority

PagerDuty

Created November 12, 2015 at 4:06 PM
Updated April 2, 2016 at 9:02 AM
Resolved November 14, 2015 at 7:17 PM