Skip to content

Commit 0731093

Browse files
authored
feat(AIP-193) Clarify Code usage in proto vs json (#1397)
Adds a callout of type "Important" that explains that `code` in google.rpc.Status is the numeric equivalent of the proto enum value found in `google.rpc.Code` while in JSON, it is the equivalent HTTP status. Closes #1396
1 parent 9bd0104 commit 0731093

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

aip/general/0193.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ descriptions, and examples:
138138
`ErrorInfo`,`LocalizedMessage`, and so on.
139139
- *Example*: Described in the [ErrorDetails](#error-details) section.
140140

141+
142+
**Important:** In the context of the`google.rpc.Status` protobuf
143+
message, the value of the field `code` is the numeric equivalent to the
144+
enum value chosen from [`google.rpc.Code`][Code]. For example, if
145+
[`INVALID_ARGUMENT`][InvalidArgument] is chosen, the value of `code`
146+
will be `3` (in the context of the Protobuf message,
147+
`google.rpc.Status`). However, when the error is expressed as JSON, as
148+
in the [sample above](#json-representation), the value of the field by
149+
the same name, `"code"`, is the HTTP status code equivalent of the
150+
selected `google.rpc.Code`. For example, the value of the field `"code"`
151+
in the JSON reply would be `400`.
152+
141153
#### [ErrorDetails][details]
142154

143155
Google defines a set of [standard detail payloads][details] for error
@@ -538,5 +550,6 @@ data instead.
538550
[Error model]: https://cloud.google.com/apis/design/errors#error_model
539551
[Help]: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L256
540552
[resource-error]: https://cloud.google.com/compute/docs/resource-error
553+
[InvalidArgument]: https://github.com/googleapis/googleapis/blob/d4acb64370d333024a167551e7da854506109ba2/google/rpc/code.proto#L52-L58
541554
542555
<!-- prettier-ignore-end -->

0 commit comments

Comments
 (0)