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