GRPCStatus.swift 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import Foundation
  2. import NIOHTTP1
  3. /// Encapsulates the result of a gRPC call.
  4. public struct GRPCStatus: Error {
  5. /// The code to return in the `grpc-status` header.
  6. public let code: StatusCode
  7. /// The message to return in the `grpc-message` header.
  8. public let message: String
  9. /// Additional HTTP headers to return in the trailers.
  10. public let trailingMetadata: HTTPHeaders
  11. public init(code: StatusCode, message: String, trailingMetadata: HTTPHeaders = HTTPHeaders()) {
  12. self.code = code
  13. self.message = message
  14. self.trailingMetadata = trailingMetadata
  15. }
  16. // Frequently used "default" statuses.
  17. /// The default status to return for succeeded calls.
  18. public static let ok = GRPCStatus(code: .ok, message: "OK")
  19. /// "Internal server error" status.
  20. public static let processingError = GRPCStatus(code: .internalError, message: "unknown error processing request")
  21. /// Status indicating that the given method is not implemented.
  22. public static func unimplemented(method: String) -> GRPCStatus {
  23. return GRPCStatus(code: .unimplemented, message: "unknown method " + method)
  24. }
  25. }