-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make errors more consistent and explanatory #103
Comments
Here is a good flowchart showing which HTTP response codes are appropriate in which situations. |
Fully agree @gamemaker1 about the need to fix error codes and messages to make it useful. But, when it comes to fully matching HTTP error code to But, I agree with you on the need to fix the API response structure in the case of any functional error with clearly defined error codes in the Can you help define the reason codes as enums for registry and credentialing micro-services? That'd be great! |
That sounds good to me 👍🏾
Sure, I would love to do that! |
Hi @pramodkvarma, As you suggested, I have created a general HTTP response format for the registry server below, including operation types, error locations and error reason codes. Please let me know if I have missed any errors that might be returned by the server, or anything that can be improved upon. Thanks! General Response Format// == Headers ==
// HTTP/1.1 {code} {status}
// X-Server: {registry-server-url}
// X-Request-Id: {request-id}
// == Response Body ==
{
// If an error occurs
"error": {
// HTTP status code
"code": {code},
// HTTP status text
"status": "{status}",
// Summary of error messages in the `errors` array
"message": "{errors-summary}",
// List errors that occurred, one by one
"errors": [
{
// Operation being carried out. Can be one of the following:
// - `CREATE_ENTITY`
// - `RETRIEVE_ENTITY`
// - `UPDATE_ENTITY`
// - `DELETE_ENTITY`
// - `MAKE_CLAIM`
// - `ATTEST_CLAIM`
// - `REJECT_CLAIM`
"operation": "{operation}",
// Location of error. Used when there is a problem with the request
// (else it's value should be null). For example, if there is a
// missing field `email` in request body, the `location` should be
// `request.body.email`. If the problem is a missing/invalid token in
// the authorisation header, the `location` should be
// `request.headers.authorization`. Can be one of the following:
// - `request.path.{field}` (URL params) => 400
// - `request.query.{field}` (Query params) => 400
// - `request.body.{field}` (Request body) => 400
// - `request.headers.{field}` (Request headers) => 401/403
// - `null`
"location": "{location}",
// Detailed error message that describes what the error is, and how it
// can be fixed. For example, for an INVALID_AUTH_TOKEN error, we might
// return the following error message: 'The auth token specified in the
// `Authorization` header is invalid or has expired. Try refreshing the
// token and retrying the same request with the new auth token.'
"message": "{error-message}",
// Machine-parsable reason. Can be one of the following:
// - `SCHEMA_VIOLATION` => 400
// - `IMPROPER_PAYLOAD_TYPE` => 400
// - `INVALID_CLAIM_SPECIFIED` => 400
// - `INVALID_AUTH_TOKEN` => 401
// - `UNAUTHORIZED_FOR_OPERATION` => 403
// - `ROUTE_NOT_FOUND` => 404
// - `ENTITY_NOT_FOUND` => 404
// - `OPERATION_NOT_ALLOWED` => 405
// - `BACKEND_ERROR` => 500, 502, 503 or 504
"reason": "{error-reason}"
}
]
},
// If the operation is successfull
"data": {
// ...
}
} Operation
Location
Reason
|
@pramodkvarma any update? Is there anything I can do to help with the implementation of this? |
Go ahead and bring this in as PR @gamemaker1. @dileepbapat can help review and merge it in. |
Will do! |
Bad Requests
Describe the bug
When I made a create entity request with two required fields missing, I got the following error:
Expected behavior
Since the status code is
400
,responseCode
should beBad Request
, notOK
. Also, it would be helpful to the client if the error explains why the error occurred and how it could be resolved. Here is an example of the error message a developer/client application would like to receive for a bad request:It would be more consistent if a similar error is returned when I make a request to send a claim for attestation, but make an error while sending the request body. Currently, I get the following error:
Since the error is regarding a bad request, the returned HTTP status code should be
400
, not404
. TheresponseCode
in the request body should beBad Request
, notOK
. An example error message that would be great (similar to the one above):Forbidden Requests
Describe the bug
When I made a get entity request with the access token for another entity, I got the following error:
Expected behavior
It would be helpful to the client if there was an error object returned that explains why the error occurred and how it could be resolved. Here is an example of the error message a client application/developer would like to receive for a forbidden request:
The same error should be returned when no access token is provided. Currently, it returns a redirect to the keycloak login page:
Even if I follow the URL and authenticate as the user, it takes me to a whitelabel error page:
Since this is an API call (
/api/v1/...
), it will most probably be a developer or their application making a request, and not a user in their browser. A developer/client application will want a403
error as a response instead of a200
code and an HTML login page from keycloak.Expired/Invalid Token
Describe the bug
When I make a request with an expired access token, I get the following error:
Expected behavior
It is not a good practice to return errors in headers.
cURL
does not even show response headers or a status code by default - a developer would be puzzled as to what happened if they didn't use certain flags to show the response headers incURL
. Here is an example of the error message an API client/developer would like to receive for a request with invalid/expired credentials:The text was updated successfully, but these errors were encountered: