CallError.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. case completionQueueShutdown
  38. static func callError(grpcCallError error: grpc_call_error) -> CallError {
  39. switch error {
  40. case GRPC_CALL_OK:
  41. return .ok
  42. case GRPC_CALL_ERROR:
  43. return .unknown
  44. case GRPC_CALL_ERROR_NOT_ON_SERVER:
  45. return .notOnServer
  46. case GRPC_CALL_ERROR_NOT_ON_CLIENT:
  47. return .notOnClient
  48. case GRPC_CALL_ERROR_ALREADY_ACCEPTED:
  49. return .alreadyAccepted
  50. case GRPC_CALL_ERROR_ALREADY_INVOKED:
  51. return .alreadyInvoked
  52. case GRPC_CALL_ERROR_NOT_INVOKED:
  53. return .notInvoked
  54. case GRPC_CALL_ERROR_ALREADY_FINISHED:
  55. return .alreadyFinished
  56. case GRPC_CALL_ERROR_TOO_MANY_OPERATIONS:
  57. return .tooManyOperations
  58. case GRPC_CALL_ERROR_INVALID_FLAGS:
  59. return .invalidFlags
  60. case GRPC_CALL_ERROR_INVALID_METADATA:
  61. return .invalidMetadata
  62. case GRPC_CALL_ERROR_INVALID_MESSAGE:
  63. return .invalidMessage
  64. case GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE:
  65. return .notServerCompletionQueue
  66. case GRPC_CALL_ERROR_BATCH_TOO_BIG:
  67. return .batchTooBig
  68. case GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH:
  69. return .payloadTypeMismatch
  70. default:
  71. return .unknown
  72. }
  73. }
  74. }