status.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 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 COMPONENTS_NTP_SNIPPETS_STATUS_H_
  5. #define COMPONENTS_NTP_SNIPPETS_STATUS_H_
  6. #include <string>
  7. namespace ntp_snippets {
  8. // This enum indicates how an operation was completed. These values are written
  9. // to logs. New enum values can be added, but existing enums must never be
  10. // renumbered or deleted and reused.
  11. enum class StatusCode {
  12. // The operation has been completed successfully.
  13. SUCCESS = 0,
  14. // The operation failed but retrying might solve the error.
  15. TEMPORARY_ERROR = 1,
  16. // The operation failed and would fail again if retried.
  17. PERMANENT_ERROR = 2,
  18. STATUS_CODE_COUNT
  19. };
  20. // This struct provides the status code of a request and an optional message
  21. // describing the status (esp. failures) in detail.
  22. struct Status {
  23. Status(StatusCode status_code, const std::string& message);
  24. ~Status();
  25. // Errors always need a message but a success does not.
  26. static Status Success();
  27. bool IsSuccess() const { return code == StatusCode::SUCCESS; }
  28. StatusCode code;
  29. // The message is not meant to be displayed to the user.
  30. std::string message;
  31. // Copy and assignment allowed.
  32. };
  33. } // namespace ntp_snippets
  34. #endif // COMPONENTS_NTP_SNIPPETS_STATUS_H_