Giorgio Desideri
Giorgio Desideri

Reputation: 179

Rest Web Service - Error Codes

thanks for reading and attentions.

My question is, exist or can I follow a table of HTTP codes to handle my error using REST Webservices ? Let me explain better:

UserRestWS (example)

I would follow a "standard" usage like HTTP codes, or other standard technique. Can you suggest me a table for this kind of problem ?

For me, it always is an 500 error code.

I googled and I find these links, not helpful for me. https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error http://www.restapitutorial.com/httpstatuscodes.html

Upvotes: 0

Views: 2692

Answers (2)

Aakash Parashar
Aakash Parashar

Reputation: 386

Here's the complete description.

+---------+-----------+------------------------------------------------------------------------+
| Sr. No. | HTTP Code |  Description                                                           |
+---------+-----------+------------------------------------------------------------------------+
|       1 |       200 | OK, shows success.                                                     |
|       2 |       201 | CREATED, when a resource is successful created using POST or PUT       |
|         |           | request. Return link to newly created resource using location          |
|         |           | header.                                                                |
|       3 |       204 | NO CONTENT, when response body is empty for example, a DELETE          |
|         |           | request.                                                               |
|       4 |       304 | NOT MODIFIED, used to reduce network bandwidth usage in case of        |
|         |           | conditional GET requests. Response body should be empty. Headers       |
|         |           | should have date, location etc.                                        |
|       5 |       400 | BAD REQUEST, states that invalid input is provided e.g.                |
|         |           | validation error, missing data.                                        |
|       6 |       401 | UNAUTHORIZED, states that user is using invalid or wrong               |
|         |           | authentication token.                                                  |
|       7 |       403 | FORBIDDEN, states that user is not having access to method being       |
|         |           | used for example, delete access without admin rights.                  |
|       8 |       404 | NOT FOUND, states that method is not available.                        |
|       9 |       409 | CONFLICT, states conflict situation while executing the method         |
|         |           | for example, adding duplicate entry.                                   |
|      10 |       500 | INTERNAL SERVER ERROR, states that server has thrown some              |
|         |           | exception while executing the method.                                  |
+---------+-----------+------------------------------------------------------------------------+

References: http://www.tutorialspoint.com/restful/restful_quick_guide.htm

Upvotes: 0

Vinay Veluri
Vinay Veluri

Reputation: 6855

enter image description here

Http codes mapping:

Creation – POST:

•   200 – success : With either user details in response / user id in response
•   204 – No content : Indicates success – with no output
•   400 – Client input error : Whatever may be error with respect to input, 
•   500 – ISE: This is mapped as generic, for all other errors.

The tweak here is you can add the error code, so as all the cases can be covered while debugging the application.

For instance:

HTTP Error code: 500.
Internal Error code: APP-USER-1001 
Description:  Failed to create user with long user name. Name cannot cross 100 chars. 

Get all users:

•   200  - success : With all the users data
•   204 – no content : No users exist in the system
•   500 – ISE: Error while retrieving the users.

If every error is mapped to 500, doesn’t make sense to API consumers to handle the situation.

Similarly the API can be applied to rest of endpoints based on cases.

Upvotes: 2

Related Questions