protobuf_http_status.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_BASE_PROTOBUF_HTTP_STATUS_H_
  5. #define REMOTING_BASE_PROTOBUF_HTTP_STATUS_H_
  6. #include <string>
  7. #include "net/base/net_errors.h"
  8. #include "net/http/http_status_code.h"
  9. namespace remoting {
  10. namespace protobufhttpclient {
  11. class Status;
  12. } // namespace protobufhttpclient
  13. class ProtobufHttpStatus {
  14. public:
  15. // This is the same as the gRPC status code.
  16. enum class Code : int {
  17. OK = 0,
  18. CANCELLED = 1,
  19. UNKNOWN = 2,
  20. INVALID_ARGUMENT = 3,
  21. DEADLINE_EXCEEDED = 4,
  22. NOT_FOUND = 5,
  23. ALREADY_EXISTS = 6,
  24. PERMISSION_DENIED = 7,
  25. UNAUTHENTICATED = 16,
  26. RESOURCE_EXHAUSTED = 8,
  27. FAILED_PRECONDITION = 9,
  28. ABORTED = 10,
  29. OUT_OF_RANGE = 11,
  30. UNIMPLEMENTED = 12,
  31. INTERNAL = 13,
  32. UNAVAILABLE = 14,
  33. DATA_LOSS = 15,
  34. };
  35. // An OK pre-defined instance.
  36. static const ProtobufHttpStatus& OK();
  37. explicit ProtobufHttpStatus(net::HttpStatusCode http_status_code);
  38. explicit ProtobufHttpStatus(net::Error net_error);
  39. explicit ProtobufHttpStatus(const protobufhttpclient::Status& status);
  40. ProtobufHttpStatus(Code code, const std::string& error_message);
  41. ~ProtobufHttpStatus();
  42. // Indicates whether the http request was successful based on the status code.
  43. bool ok() const;
  44. // The instance's error code.
  45. Code error_code() const { return error_code_; }
  46. // The message that describes the error.
  47. const std::string& error_message() const { return error_message_; }
  48. private:
  49. Code error_code_;
  50. std::string error_message_;
  51. };
  52. } // namespace remoting
  53. #endif // REMOTING_BASE_PROTOBUF_HTTP_STATUS_H_