authgear / authgear/authgear-server
Improve Error Response in APIs
- Dominant language
- Go
- Stars
- 2k
- Forks
- 125
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 32
Description
We shall improve the error response at once, currently, there are several problems:
1. `name` is type of error which is confusing.
2. `code` is just HTTP status code, which doesn't have to be in JSON response.
3. `info` doesn't have standardized fields or documentation.
So instead of:
```
"error": {
"name": "Invalid",
"reason": "InvariantViolated",
"message": "identity already exists",
"code": 400,
"info": {
"cause": {
"kind": "DuplicatedIdentity"
}
}
}
```
We shall change to:
```
"error": {
"type": "TypeOfError"
"code": "Short String for the Error"
"message": "Human readable message"
"info": { }
}
```
The main changes from the current design are:
* Use `type` instead of `name` for the category of error. Using `name` as `type` is very confusing. We also should have a list of `type` possible values.
* HTTP status code should go back to HTTP response header
* `code` and `message` are the actual error
* We shall study the APIs used this error scheme, and try to come up with a standardized object for `info`, otherwise it is not usable at all (or else we need to write a spec to indicate what error will have which `info`, but it is not as good as a standardized object.
### Original rename suggested by Louis
* DuplicatedIdentity becomes its own error
* IdentityModifyDisabled becomes its own error
* NoAuthenticator becomes its own error
* MismatchedUser becomes its own error
* Keep ErrClaimNotVerifiable unchanged.
Contributor guide
Assessment
This issue has not been assessed yet.