blob: 1fbf9c1b68762a8068496fae9c9d78c897d74acb [file] [log] [blame]
Jan Tattermuscha7fff862015-02-13 11:08:08 -08001#region Copyright notice and license
2
Jan Tattermuschaf77b3d2015-02-13 11:22:21 -08003// Copyright 2015, Google Inc.
Jan Tattermuscha7fff862015-02-13 11:08:08 -08004// All rights reserved.
Craig Tiller190d3602015-02-18 09:23:38 -08005//
Jan Tattermuscha7fff862015-02-13 11:08:08 -08006// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
Craig Tiller190d3602015-02-18 09:23:38 -08009//
Jan Tattermuscha7fff862015-02-13 11:08:08 -080010// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
Craig Tiller190d3602015-02-18 09:23:38 -080019//
Jan Tattermuscha7fff862015-02-13 11:08:08 -080020// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
Jan Tattermuscha7608b02015-02-03 17:54:38 -080034using System;
35
Jan Tattermusch30868622015-02-19 09:22:33 -080036namespace Grpc.Core
Jan Tattermuscha7608b02015-02-03 17:54:38 -080037{
38 // TODO: element names should changed to comply with C# naming conventions.
39 /// <summary>
Jan Tattermusch30868622015-02-19 09:22:33 -080040 /// based on grpc_status_code from grpc/status.h
Jan Tattermuscha7608b02015-02-03 17:54:38 -080041 /// </summary>
42 public enum StatusCode
43 {
44 /* Not an error; returned on success
45
46 HTTP Mapping: 200 OK */
Jan Tattermusch30868622015-02-19 09:22:33 -080047 OK = 0,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080048 /* The operation was cancelled (typically by the caller).
49
50 HTTP Mapping: 499 Client Closed Request */
Jan Tattermusch30868622015-02-19 09:22:33 -080051 Cancelled = 1,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080052 /* Unknown error. An example of where this error may be returned is
53 if a Status value received from another address space belongs to
54 an error-space that is not known in this address space. Also
55 errors raised by APIs that do not return enough error information
56 may be converted to this error.
57
58 HTTP Mapping: 500 Internal Server Error */
Jan Tattermusch30868622015-02-19 09:22:33 -080059 Unknown = 2,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080060 /* Client specified an invalid argument. Note that this differs
61 from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments
62 that are problematic regardless of the state of the system
63 (e.g., a malformed file name).
64
65 HTTP Mapping: 400 Bad Request */
Jan Tattermusch30868622015-02-19 09:22:33 -080066 InvalidArgument = 3,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080067 /* Deadline expired before operation could complete. For operations
68 that change the state of the system, this error may be returned
69 even if the operation has completed successfully. For example, a
70 successful response from a server could have been delayed long
71 enough for the deadline to expire.
72
73 HTTP Mapping: 504 Gateway Timeout */
Jan Tattermusch30868622015-02-19 09:22:33 -080074 DeadlineExceeded = 4,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080075 /* Some requested entity (e.g., file or directory) was not found.
76
77 HTTP Mapping: 404 Not Found */
Jan Tattermusch30868622015-02-19 09:22:33 -080078 NotFound = 5,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080079 /* Some entity that we attempted to create (e.g., file or directory)
80 already exists.
81
82 HTTP Mapping: 409 Conflict */
Jan Tattermusch30868622015-02-19 09:22:33 -080083 AlreadyExists = 6,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080084 /* The caller does not have permission to execute the specified
85 operation. PERMISSION_DENIED must not be used for rejections
86 caused by exhausting some resource (use RESOURCE_EXHAUSTED
87 instead for those errors). PERMISSION_DENIED must not be
88 used if the caller can not be identified (use UNAUTHENTICATED
89 instead for those errors).
90
91 HTTP Mapping: 403 Forbidden */
Jan Tattermusch30868622015-02-19 09:22:33 -080092 PermissionDenied = 7,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080093 /* The request does not have valid authentication credentials for the
94 operation.
95
96 HTTP Mapping: 401 Unauthorized */
Jan Tattermusch30868622015-02-19 09:22:33 -080097 Unauthenticated = 16,
Jan Tattermuscha7608b02015-02-03 17:54:38 -080098 /* Some resource has been exhausted, perhaps a per-user quota, or
99 perhaps the entire file system is out of space.
100
101 HTTP Mapping: 429 Too Many Requests */
Jan Tattermusch30868622015-02-19 09:22:33 -0800102 ResourceExhausted = 8,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800103 /* Operation was rejected because the system is not in a state
104 required for the operation's execution. For example, directory
105 to be deleted may be non-empty, an rmdir operation is applied to
106 a non-directory, etc.
107
108 A litmus test that may help a service implementor in deciding
109 between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
110 (a) Use UNAVAILABLE if the client can retry just the failing call.
111 (b) Use ABORTED if the client should retry at a higher-level
112 (e.g., restarting a read-modify-write sequence).
113 (c) Use FAILED_PRECONDITION if the client should not retry until
114 the system state has been explicitly fixed. E.g., if an "rmdir"
115 fails because the directory is non-empty, FAILED_PRECONDITION
116 should be returned since the client should not retry unless
117 they have first fixed up the directory by deleting files from it.
118 (d) Use FAILED_PRECONDITION if the client performs conditional
119 REST Get/Update/Delete on a resource and the resource on the
120 server does not match the condition. E.g., conflicting
121 read-modify-write on the same resource.
122
123 HTTP Mapping: 400 Bad Request
124
125 NOTE: HTTP spec says 412 Precondition Failed should only be used if
126 the request contains Etag related headers. So if the server does see
127 Etag related headers in the request, it may choose to return 412
128 instead of 400 for this error code. */
Jan Tattermusch30868622015-02-19 09:22:33 -0800129 FailedPrecondition = 9,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800130 /* The operation was aborted, typically due to a concurrency issue
131 like sequencer check failures, transaction aborts, etc.
132
133 See litmus test above for deciding between FAILED_PRECONDITION,
134 ABORTED, and UNAVAILABLE.
135
136 HTTP Mapping: 409 Conflict */
Jan Tattermusch30868622015-02-19 09:22:33 -0800137 Aborted = 10,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800138 /* Operation was attempted past the valid range. E.g., seeking or
139 reading past end of file.
140
141 Unlike INVALID_ARGUMENT, this error indicates a problem that may
142 be fixed if the system state changes. For example, a 32-bit file
143 system will generate INVALID_ARGUMENT if asked to read at an
144 offset that is not in the range [0,2^32-1], but it will generate
145 OUT_OF_RANGE if asked to read from an offset past the current
146 file size.
147
148 There is a fair bit of overlap between FAILED_PRECONDITION and
149 OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific
150 error) when it applies so that callers who are iterating through
151 a space can easily look for an OUT_OF_RANGE error to detect when
152 they are done.
153
154 HTTP Mapping: 400 Bad Request */
Jan Tattermusch30868622015-02-19 09:22:33 -0800155 OutOfRange = 11,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800156 /* Operation is not implemented or not supported/enabled in this service.
157
158 HTTP Mapping: 501 Not Implemented */
Jan Tattermusch30868622015-02-19 09:22:33 -0800159 Unimplemented = 12,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800160 /* Internal errors. Means some invariants expected by underlying
161 system has been broken. If you see one of these errors,
162 something is very broken.
163
164 HTTP Mapping: 500 Internal Server Error */
Jan Tattermusch30868622015-02-19 09:22:33 -0800165 Internal = 13,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800166 /* The service is currently unavailable. This is a most likely a
167 transient condition and may be corrected by retrying with
168 a backoff.
169
170 See litmus test above for deciding between FAILED_PRECONDITION,
171 ABORTED, and UNAVAILABLE.
172
173 HTTP Mapping: 503 Service Unavailable */
Jan Tattermusch30868622015-02-19 09:22:33 -0800174 Unavailable = 14,
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800175 /* Unrecoverable data loss or corruption.
176
177 HTTP Mapping: 500 Internal Server Error */
Jan Tattermusch30868622015-02-19 09:22:33 -0800178 DataLoss = 15
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800179 }
180}
181