Errors
(Difference between revisions)
(→JSON Structure) |
|||
Line 50: | Line 50: | ||
{| | {| | ||
− | ! align="left" width=" | + | ! align="left" width="150px" | Field |
− | ! align="left" width=" | + | ! align="left" width="150px" | Presence |
! align="left" | Description | ! align="left" | Description | ||
|- | |- |
Revision as of 17:33, 5 May 2015
In the case of errors in the request, an error code will be set properly. The response status will be set to the respective HTTP status code and the body may contain a JSON value with more information concerning the error.
The status codes and JSON structure are described below. However, some APIs may differ slightly. In such case, refer to the specific API documentation for further information.
HTTP Status Codes
The following table contains the main codes and their simple descriptions. See specific API documentations for more detailed information.
Code | Status | Description |
---|---|---|
400 | bad_request | Some required parameter was not informed. |
401 | unauthorized | The authentication is wrong. See Authentication. |
403 | forbidden | The request wan not accepted due to semantic permission errors. |
404 | not_found | Some resource was not found. |
406 | not_acceptable | The requested format is not accepted. Make sure the "Content-Type" header is set correctly. |
409 | conflict | A semantic conflict happened. |
422 | unprocessable_entity | A validation error occurred. |
500 | internal_server_error | An unknown error happened. |
JSON Structure
The response JSON is formatted as a hash in the format field:value, the following fields are returned:
Field | Presence | Description |
---|---|---|
error | required | Error code. One of: authentication_failed, bad_request, conflict, forbidden, internal_server_error, invalid_parameters, missing_parameters, not_acceptable, not_found, unauthorized, unprocessable_entity. |
error_description | required | Human readable error message. |
errors | optional | Array with error descriptions. Each array element is either a string with an error message or a hash in the format field:value with the following fields: |
attribute | required | Name of the attribute with error. If the error has no associated attribute, its value is set to "base". |
message | required | Human readable error message. |
code | required | Error code. See the JSON Error Codes table below for detailed information. |
value | optional | Extra field to inform which value the error refers to. |
count | optional | Extra integer field to inform which count the error refers to. |
JSON Error Codes
The following codes are used in the error description:
Code | Description | Possible Extra fields |
---|---|---|
inclusion | The attribute value is not one of the possible values. | |
exclusion | The attribute value is reserved. | |
invalid | The attribute value is invalid. | value |
confirmation | The attribute doesn't match the confirmation. | |
accepted | The attribute must be accepted. | |
empty | The attribute can't be empty. | |
blank | The attribute can't be blank. | |
too_long | The attribute is too long. (Maximum of count characters) | count |
too_short | The attribute is too short. (Minimum of count characters) | count |
wrong_length | The attribute has the wrong length. (Should be count characters) | count |
not_a_number | The attribute must be a number. | |
not_an_integer | The attribute must be an integer. | |
greater_than | The attribute must be greater than count. | count |
greater_than_or_equal_to | The attribute must be greater than or equal to count. | count |
equal_to | The attribute must be equal to count. | count |
less_than | The attribute must be less than count. | count |
less_than_or_equal_to | The attribute must be less than or equal to count. | count |
odd | The attribute must be odd. | |
even | The attribute must be even. | |
taken | The attribute value has already been taken. | |
must_be_present | The attribute value must be present. | value |
invalid_email | The attribute must be a valid email. | |
repeated | The attribute value must be different from last count ones. | count |