Skip to content
Eldelshell edited this page Apr 27, 2020 · 2 revisions

Error Handling

Amforeas will try to interpret the miriad of errors a JDBC driver might return and convert it to the corresponding HTTP error code.

Every error response contains the following:

  • Error code in the HTTP Header
  • Success to false
  • A message string with an explanation of the error

Example:

$ curl -i -X GET -H "Accept: application/json;version=1"  "http://localhost:8080/amforeas/demo1/user/99"
HTTP/1.1 404 Not Found
Content-Type: application/json
Content-Location: user
Content-Length: 39
{"success":false,"message":"Not Found"}

If the error comes directly from the RDBMS and depending on the error, amforeas will forward it as a 400 error:

$ curl -i -X GET -H "Accept: application/json;version=1"  "http://localhost:8080/amforeas/demo1/user/x99"
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Location: user
{
  "success":false,
  "message":"data exception: invalid character value for cast Query: SELECT * FROM user WHERE id = ? ORDER BY id ASC LIMIT 25 OFFSET 0 Parameters: [x99],
  "SQLState":"22018",
  "SQLCode":"-3438"
}

A part from the previously mentioned fields, here you receive two more: SQLState and SQLCode. You can read more in the SQL ISO1992

Empty results

It's important to note that if a table/view is empty, you won't receive an error if you try to retrieve all its resources:

$ curl -i -X GET -H "Accept: application/json;version=1"  "http://localhost:8080/amforeas/demo1/empty"
HTTP/1.1 200 OK
Content-Count: 0
Content-Location: empty
Content-Length: 27
{"success":true,"cells":[]}

But, if you try to access a non-existent resource, a 404 will be returned:

$ curl -i -X GET -H "Accept: application/json"  "http://localhost:8080/amforeas/demo1/empty/0"
HTTP/1.1 404 Not Found

All Requests

404 (Not Found) The resource is not available.

400 (Bad Request) The operation you're trying to perform can't be.

500 (Internal Server Error) For some reason amforeas failed to perform the operation.

GET Requests

200 (OK) Everything is fine.

POST Requests

201 (Created) The new resource has been created. The new resource comes with the response.

204 (No Content) The new resource has been created. The response is empty.

PUT Requests

200 (OK) The record was updated. The resource comes with the response.

DELETE Requests

200 (OK) The record was deleted