Error Handling
hiroara opened this issue · 0 comments
hiroara commented
Current Behavior
Currently, scnnr-js does not handle any errors from a server.
> cli.recognizeURL('/example.com/dummy.jpg').catch(error => console.error(`${error.name}: ${error.message}`))
// => Error: Request failed with status code 422
Expected Behavior
The API server will return errors as a specific format. (See docs)
scnnr-js should handle and parse the error responses.
> cli.recognizeURL('/example.com/dummy.jpg').catch(error => console.error(`${error.name}: ${error.message}`))
// => UnprocessableEntity: Unexpected scheme of URL: /example.com/dummy.jpg
Error Cases
- 403
- This error has special format:
{"message":"Forbidden"}
- Occurred by: Request a recognition without
x-api-key
header
- This error has special format:
- 404
- Error type:
not-found
- Occurred by:
GET /recognitions/*
with non-existing key (e.g.GET /recognitions/non-existing-key
)
- Error type:
- 422
- Error type:
unprocessable-entity
- Occurred by:
POST /remote/recognitions
with invalid URL (e.g./etc/shadow
)
- Error type:
- 429
- This error has special format:
{"message":"Too Many Requests"}
- Occurred by: Exceed request quota
- This error has special format:
- 500
- Error type:
internal-server-error
- Occurred by: Unexpected internal error on server (Cannot reproduce with a request from client)
- Error type: