Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 501 for java.lang.UnsupportedOperationException

I have a generic REST service layer written to Java modules which can be plugged in. If any of the desired operation is not supported by a Module (GET/POST/PUT/DELETE of a Resource), the module throws java.lang.UnsupportedOperationException or an equivalent Exception Type that I have.

So, can I return a HTTP 501 Error Code to the client in this case?

like image 940
Anil G Avatar asked Jul 10 '12 06:07

Anil G


1 Answers

In this case you should use 405 Method Not Allowed (all quotes from Wikipedia):

A request was made of a resource using a request method not supported by that resource; for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource.

501 is reasonable:

The server either does not recognise the request method, or it lacks the ability to fulfill the request.

but I would keep it for operations that you plan to implement in the near future.

like image 66
Tomasz Nurkiewicz Avatar answered Nov 10 '22 10:11

Tomasz Nurkiewicz