GRPCTypes.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. *
  3. * Copyright 2019 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #import <Foundation/Foundation.h>
  19. /**
  20. * gRPC error codes.
  21. * Note that a few of these are never produced by the gRPC libraries, but are of
  22. * general utility for server applications to produce.
  23. */
  24. typedef NS_ENUM(NSUInteger, GRPCErrorCode) {
  25. /** The operation was cancelled (typically by the caller). */
  26. GRPCErrorCodeCancelled = 1,
  27. /**
  28. * Unknown error. Errors raised by APIs that do not return enough error
  29. * information may be converted to this error.
  30. */
  31. GRPCErrorCodeUnknown = 2,
  32. /**
  33. * The client specified an invalid argument. Note that this differs from
  34. * FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
  35. * problematic regardless of the state of the server (e.g., a malformed file
  36. * name).
  37. */
  38. GRPCErrorCodeInvalidArgument = 3,
  39. /**
  40. * Deadline expired before operation could complete. For operations that
  41. * change the state of the server, this error may be returned even if the
  42. * operation has completed successfully. For example, a successful response
  43. * from the server could have been delayed long enough for the deadline to
  44. * expire.
  45. */
  46. GRPCErrorCodeDeadlineExceeded = 4,
  47. /** Some requested entity (e.g., file or directory) was not found. */
  48. GRPCErrorCodeNotFound = 5,
  49. /** Some entity that we attempted to create (e.g., file or directory) already
  50. exists. */
  51. GRPCErrorCodeAlreadyExists = 6,
  52. /**
  53. * The caller does not have permission to execute the specified operation.
  54. * PERMISSION_DENIED isn't used for rejections caused by exhausting some
  55. * resource (RESOURCE_EXHAUSTED is used instead for those errors).
  56. * PERMISSION_DENIED doesn't indicate a failure to identify the caller
  57. * (UNAUTHENTICATED is used instead for those errors).
  58. */
  59. GRPCErrorCodePermissionDenied = 7,
  60. /**
  61. * The request does not have valid authentication credentials for the
  62. * operation (e.g. the caller's identity can't be verified).
  63. */
  64. GRPCErrorCodeUnauthenticated = 16,
  65. /** Some resource has been exhausted, perhaps a per-user quota. */
  66. GRPCErrorCodeResourceExhausted = 8,
  67. /**
  68. * The RPC was rejected because the server is not in a state required for the
  69. * procedure's execution. For example, a directory to be deleted may be
  70. * non-empty, etc. The client should not retry until the server state has been
  71. * explicitly fixed (e.g. by performing another RPC). The details depend on
  72. * the service being called, and should be found in the NSError's userInfo.
  73. */
  74. GRPCErrorCodeFailedPrecondition = 9,
  75. /**
  76. * The RPC was aborted, typically due to a concurrency issue like sequencer
  77. * check failures, transaction aborts, etc. The client should retry at a
  78. * higher-level (e.g., restarting a read- modify-write sequence).
  79. */
  80. GRPCErrorCodeAborted = 10,
  81. /**
  82. * The RPC was attempted past the valid range. E.g., enumerating past the end
  83. * of a list. Unlike INVALID_ARGUMENT, this error indicates a problem that may
  84. * be fixed if the system state changes. For example, an RPC to get elements
  85. * of a list will generate INVALID_ARGUMENT if asked to return the element at
  86. * a negative index, but it will generate OUT_OF_RANGE if asked to return the
  87. * element at an index past the current size of the list.
  88. */
  89. GRPCErrorCodeOutOfRange = 11,
  90. /** The procedure is not implemented or not supported/enabled in this server.
  91. */
  92. GRPCErrorCodeUnimplemented = 12,
  93. /**
  94. * Internal error. Means some invariant expected by the server application or
  95. * the gRPC library has been broken.
  96. */
  97. GRPCErrorCodeInternal = 13,
  98. /**
  99. * The server is currently unavailable. This is most likely a transient
  100. * condition and may be corrected by retrying with a backoff. Note that it is
  101. * not always safe to retry non-idempotent operations.
  102. */
  103. GRPCErrorCodeUnavailable = 14,
  104. /** Unrecoverable data loss or corruption. */
  105. GRPCErrorCodeDataLoss = 15,
  106. };
  107. /**
  108. * Safety remark of a gRPC method as defined in RFC 2616 Section 9.1
  109. */
  110. typedef NS_ENUM(NSUInteger, GRPCCallSafety) {
  111. /**
  112. * Signal that there is no guarantees on how the call affects the server
  113. * state.
  114. */
  115. GRPCCallSafetyDefault = 0,
  116. /** Signal that the call is idempotent. gRPC is free to use PUT verb. */
  117. GRPCCallSafetyIdempotentRequest = 1,
  118. /**
  119. * Signal that the call is cacheable and will not affect server state. gRPC is
  120. * free to use GET verb.
  121. */
  122. GRPCCallSafetyCacheableRequest = 2,
  123. };
  124. /**
  125. * Compression algorithm to be used by a gRPC call.
  126. *
  127. * <b>This enumeration and corresponding call option GRPCCallOptions.transportType are deprecated by
  128. * the call option GRPCCallOptions.transport. </b>
  129. */
  130. typedef NS_ENUM(NSUInteger, GRPCCompressionAlgorithm) {
  131. GRPCCompressNone = 0,
  132. GRPCCompressDeflate,
  133. GRPCCompressGzip,
  134. GRPCStreamCompressGzip,
  135. };
  136. /** GRPCCompressAlgorithm is deprecated. */
  137. typedef GRPCCompressionAlgorithm GRPCCompressAlgorithm;
  138. /** The transport to be used by a gRPC call */
  139. typedef NS_ENUM(NSUInteger, GRPCTransportType) {
  140. GRPCTransportTypeDefault = 0,
  141. /** gRPC internal HTTP/2 stack with BoringSSL */
  142. GRPCTransportTypeChttp2BoringSSL = 0,
  143. /** Cronet stack */
  144. GRPCTransportTypeCronet,
  145. /** Insecure channel. FOR TEST ONLY! */
  146. GRPCTransportTypeInsecure,
  147. };
  148. /** Domain of NSError objects produced by gRPC. */
  149. extern NSString* _Nonnull const kGRPCErrorDomain;
  150. /**
  151. * Keys used in |NSError|'s |userInfo| dictionary to store the response headers
  152. * and trailers sent by the server.
  153. */
  154. extern NSString* _Nonnull const kGRPCHeadersKey;
  155. extern NSString* _Nonnull const kGRPCTrailersKey;
  156. /** The id of a transport implementation. */
  157. typedef char* _Nonnull GRPCTransportID;
  158. /**
  159. * Implement this protocol to provide a token to gRPC when a call is initiated.
  160. */
  161. @protocol GRPCAuthorizationProtocol
  162. /**
  163. * This method is called when gRPC is about to start the call. When OAuth token is acquired,
  164. * \a handler is expected to be called with \a token being the new token to be used for this call.
  165. */
  166. - (void)getTokenWithHandler:(void (^_Nonnull)(NSString* _Nullable token))handler;
  167. @end