-
Notifications
You must be signed in to change notification settings - Fork 3
Alternate AIP-193 recommendation #45
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
2ee6e9b
0908529
568e0fc
1519d97
40cff57
1aa3dee
9172c51
6233a69
421a3fd
2626d27
1c083f9
77ee548
e66cf0d
c499945
214fac2
dcc55d8
3cf2ce2
97eb647
1de2d49
10c62b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Errors | ||
|
||
Error handling is an important part of designing simple and intuitive APIs. | ||
Consistent error handling allows developers to know how to expect to receive | ||
errors, and to reduce boilerplate by having common error-handling logic, rather | ||
than being expected to constantly add verbose error handling everywhere. | ||
|
||
## Guidance | ||
|
||
Services **must** clearly distinguish successful responses from error responses | ||
by using appropriate HTTP codes: | ||
- Informational responses **must** use HTTP status codes between 100 and 199. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allowing 100 to 199 status code is per RFC 7807 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure what an "informational response" is - and I'd rather not have to go to the HTTP RFCs to find out. Does this range indicate success or failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These may not indicate success or failure. These are often used to indicate intermediate status of an HTTP request. For instance, a server that supports HTTP/2 can respond with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding clarification |
||
- Successful responses **must** use HTTP status codes between 200 and 399. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are 3xx responses really successful in the context of APIs? 304 could be considered successful, but anything else really suggests further action. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. 3XX should mean redirection. Updating this |
||
- Errors indicating a problem with the user's request **must** use HTTP status | ||
codes between 400 and 499. | ||
- Errors indicating a problem with the server's handling of an valid request | ||
**must** use HTTP status codes between 500 and 599. | ||
|
||
### Structure | ||
|
||
Error responses **should** conform to the following interface: | ||
|
||
```typescript | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why typescript when the existing aip.dev is using protobuf / OpenAPI? https://aip-dev.github.io/aip.dev/136. |
||
interface Error { | ||
//A machine-readable code indicating the type of error (like `name_too_long`). This value is parseable for programmatic error handling. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super-nit: |
||
code: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably specify that strings should be comparable using ordinal comparisons - not case-insensitively, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding clarification below. One thing to note is the recommendation is to use only lowercase letters here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per discussion, consensus was to to stick with |
||
|
||
//A human readable description of the problem. Should not change from occurrence to occurrence (except for localization). | ||
title?: string | ||
|
||
//The HTTP status code between 100 and 500 | ||
status?: integer | ||
|
||
//A human-readable explanation specific to this occurrence of the problem | ||
detail?: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shwoodard @lukesneeringer |
||
|
||
//A unique identifier that identifies the specific occurrence of the problem. Can be provided to the API owner for debugging purposes. | ||
id?: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternate options:
Consensus was to use |
||
} | ||
``` | ||
|
||
- The `title` field is intended for consumption by humans, and therefore | ||
**may** change, even within a single version. | ||
- The `code` field is intended to have code written against it, and therefore | ||
**must not** change. Values for this field should be 0-63 characters, and use | ||
only lower-case letters, numbers, and the `-` character. | ||
|
||
|
||
|
||
### Messages | ||
|
||
Error messages **should** help a reasonably technical user understand and | ||
resolve the issue, and **should not** assume that the user is an expert in the | ||
particular API. Additionally, error messages **must not** assume that the user | ||
will know anything about its underlying implementation. | ||
|
||
Error messages **should** be brief but actionable. Any extra information | ||
**should** be provided in a `details` field. If even more information is | ||
necessary, the service **should** provide a link where a reader can get more | ||
information or ask questions to help resolve the issue. | ||
|
||
### Localization | ||
|
||
Error messages **must** be in American English. If a localized error message is | ||
also required, the service **should** provide the following structure within | ||
its `details`: | ||
|
||
```typescript | ||
interface LocalizedMessage { | ||
// The locale for this error message. | ||
// Follows the spec defined at http://www.rfc-editor.org/rfc/bcp/bcp47.txt. | ||
// Examples: 'en-US', 'de-CH', 'es-MX' | ||
locale: string; | ||
|
||
// The localized error message in the above locale. | ||
message: string; | ||
} | ||
``` | ||
|
||
### Partial errors | ||
|
||
APIs **should not** support partial errors. Partial errors add significant | ||
complexity for users, because they usually sidestep the use of error codes, or | ||
move those error codes into the response message, where the user must write | ||
specialized error handling logic to address the problem. | ||
|
||
However, occasionally partial errors are unavoidable, particularly in bulk | ||
operations where it would be hostile to users to fail an entire large request | ||
because of a problem with a single entry. | ||
|
||
Methods that require partial errors **should** use long-running operations (as | ||
described in AIP-151), and the method **should** put partial failure | ||
information in the metadata message. The errors themselves **must** still be | ||
represented with an error object. | ||
|
||
## Further reading | ||
|
||
- For which error codes to retry, see AIP-194. | ||
|
||
## Changelog | ||
|
||
- **2020-09-02**: Refactored errors AIP to be more generic. | ||
- **2020-01-22**: Added a reference to the `ErrorInfo` message in gRPC. | ||
- **2019-10-14**: Added guidance restricting error message mutability to if | ||
there is a machine-readable identifier present. | ||
- **2019-09-23**: Added guidance about error message strings being able to | ||
change. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to change anything in this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like google.aip.dev moves this front-matter to the file itself (which I tend to agree with) https://raw.githubusercontent.com/aip-dev/google.aip.dev/master/aip/general/0001.md. Is there an outstanding issue to move this to the more succinct format? |
||
id: 193 | ||
state: approved | ||
created: 2019-07-26 | ||
placement: | ||
category: polish | ||
order: 30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since there already is protobuf-level guidance, why not include protobuf? or does it translate? https://google.aip.dev/193.
I'm thinking about how to reconcile this proposal with existing practices in google.aip.dev (which, as the only public repository up until now, has served as the base of other forks IIUC).