syncer_error.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2012 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_SYNC_BASE_SYNCER_ERROR_H_
  5. #define COMPONENTS_SYNC_BASE_SYNCER_ERROR_H_
  6. #include <string>
  7. namespace syncer {
  8. // This class describes all the possible results of a sync cycle. It should be
  9. // passed by value.
  10. class SyncerError {
  11. public:
  12. // This enum should be in sync with SyncerErrorValues in enums.xml. These
  13. // values are persisted to logs. Entries should not be renumbered and numeric
  14. // values should never be reused.
  15. enum Value {
  16. UNSET = 0, // Default value.
  17. CANNOT_DO_WORK = 1, // A model worker could not process a work item.
  18. NETWORK_CONNECTION_UNAVAILABLE = 2, // Connectivity failure.
  19. NETWORK_IO_ERROR = 3, // Response buffer read error.
  20. SYNC_SERVER_ERROR = 4, // Non auth HTTP error.
  21. SYNC_AUTH_ERROR = 5, // HTTP auth error.
  22. // Based on values returned by server. Most are defined in sync.proto.
  23. // Deprecated: SERVER_RETURN_INVALID_CREDENTIAL = 6,
  24. SERVER_RETURN_UNKNOWN_ERROR = 7,
  25. SERVER_RETURN_THROTTLED = 8,
  26. SERVER_RETURN_TRANSIENT_ERROR = 9,
  27. SERVER_RETURN_MIGRATION_DONE = 10,
  28. SERVER_RETURN_CLEAR_PENDING = 11,
  29. SERVER_RETURN_NOT_MY_BIRTHDAY = 12,
  30. SERVER_RETURN_CONFLICT = 13,
  31. SERVER_RESPONSE_VALIDATION_FAILED = 14,
  32. SERVER_RETURN_DISABLED_BY_ADMIN = 15,
  33. // Deprecated: SERVER_RETURN_USER_ROLLBACK = 16,
  34. SERVER_RETURN_PARTIAL_FAILURE = 17,
  35. SERVER_RETURN_CLIENT_DATA_OBSOLETE = 18,
  36. SERVER_RETURN_ENCRYPTION_OBSOLETE = 19,
  37. // A datatype decided the sync cycle needed to be performed again.
  38. DATATYPE_TRIGGERED_RETRY = 20,
  39. SERVER_MORE_TO_DOWNLOAD = 21,
  40. SYNCER_OK = 22,
  41. kMaxValue = SYNCER_OK,
  42. };
  43. constexpr SyncerError() = default;
  44. // Note: NETWORK_CONNECTION_UNAVAILABLE, SYNC_SERVER_ERROR, and
  45. // SYNC_AUTH_ERROR are *not* valid inputs for this constructor. These types
  46. // of errors must be created via the factory functions below.
  47. explicit SyncerError(Value value);
  48. static SyncerError NetworkConnectionUnavailable(int net_error_code);
  49. static SyncerError HttpError(int http_status_code);
  50. Value value() const { return value_; }
  51. std::string ToString() const;
  52. // Helper to check that |error| is set to something (not UNSET) and is not
  53. // SYNCER_OK or SERVER_MORE_TO_DOWNLOAD.
  54. bool IsActualError() const;
  55. private:
  56. constexpr SyncerError(Value value, int net_error_code, int http_status_code)
  57. : value_(value),
  58. net_error_code_(net_error_code),
  59. http_status_code_(http_status_code) {}
  60. Value value_ = UNSET;
  61. // TODO(crbug.com/947443): Consider storing the actual enums.
  62. int net_error_code_ = 0;
  63. int http_status_code_ = 0;
  64. };
  65. } // namespace syncer
  66. #endif // COMPONENTS_SYNC_BASE_SYNCER_ERROR_H_