CallError.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2016, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if SWIFT_PACKAGE
  17. import CgRPC
  18. import Dispatch
  19. #endif
  20. import Foundation
  21. public enum CallError: Error {
  22. case ok
  23. case unknown
  24. case notOnServer
  25. case notOnClient
  26. case alreadyAccepted
  27. case alreadyInvoked
  28. case notInvoked
  29. case alreadyFinished
  30. case tooManyOperations
  31. case invalidFlags
  32. case invalidMetadata
  33. case invalidMessage
  34. case notServerCompletionQueue
  35. case batchTooBig
  36. case payloadTypeMismatch
  37. static func callError(grpcCallError error: grpc_call_error) -> CallError {
  38. switch error {
  39. case GRPC_CALL_OK:
  40. return .ok
  41. case GRPC_CALL_ERROR:
  42. return .unknown
  43. case GRPC_CALL_ERROR_NOT_ON_SERVER:
  44. return .notOnServer
  45. case GRPC_CALL_ERROR_NOT_ON_CLIENT:
  46. return .notOnClient
  47. case GRPC_CALL_ERROR_ALREADY_ACCEPTED:
  48. return .alreadyAccepted
  49. case GRPC_CALL_ERROR_ALREADY_INVOKED:
  50. return .alreadyInvoked
  51. case GRPC_CALL_ERROR_NOT_INVOKED:
  52. return .notInvoked
  53. case GRPC_CALL_ERROR_ALREADY_FINISHED:
  54. return .alreadyFinished
  55. case GRPC_CALL_ERROR_TOO_MANY_OPERATIONS:
  56. return .tooManyOperations
  57. case GRPC_CALL_ERROR_INVALID_FLAGS:
  58. return .invalidFlags
  59. case GRPC_CALL_ERROR_INVALID_METADATA:
  60. return .invalidMetadata
  61. case GRPC_CALL_ERROR_INVALID_MESSAGE:
  62. return .invalidMessage
  63. case GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE:
  64. return .notServerCompletionQueue
  65. case GRPC_CALL_ERROR_BATCH_TOO_BIG:
  66. return .batchTooBig
  67. case GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH:
  68. return .payloadTypeMismatch
  69. default:
  70. return .unknown
  71. }
  72. }
  73. }