57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/mailchimp.rb', line 57
def cast_error(body)
error_map = {
'ValidationError' => ValidationError,
'ServerError_MethodUnknown' => ServerMethodUnknownError,
'ServerError_InvalidParameters' => ServerInvalidParametersError,
'Unknown_Exception' => UnknownExceptionError,
'Request_TimedOut' => RequestTimedOutError,
'Zend_Uri_Exception' => ZendUriExceptionError,
'PDOException' => PDOExceptionError,
'Avesta_Db_Exception' => AvestaDbExceptionError,
'XML_RPC2_Exception' => XMLRPC2ExceptionError,
'XML_RPC2_FaultException' => XMLRPC2FaultExceptionError,
'Too_Many_Connections' => TooManyConnectionsError,
'Parse_Exception' => ParseExceptionError,
'User_Unknown' => UserUnknownError,
'User_Disabled' => UserDisabledError,
'User_DoesNotExist' => UserDoesNotExistError,
'User_NotApproved' => UserNotApprovedError,
'Invalid_ApiKey' => InvalidApiKeyError,
'User_UnderMaintenance' => UserUnderMaintenanceError,
'Invalid_AppKey' => InvalidAppKeyError,
'Invalid_IP' => InvalidIPError,
'User_DoesExist' => UserDoesExistError,
'User_InvalidRole' => UserInvalidRoleError,
'User_InvalidAction' => UserInvalidActionError,
'User_MissingEmail' => UserMissingEmailError,
'User_CannotSendCampaign' => UserCannotSendCampaignError,
'User_MissingModuleOutbox' => UserMissingModuleOutboxError,
'User_ModuleAlreadyPurchased' => UserModuleAlreadyPurchasedError,
'User_ModuleNotPurchased' => UserModuleNotPurchasedError,
'User_NotEnoughCredit' => UserNotEnoughCreditError,
'MC_InvalidPayment' => MCInvalidPaymentError,
'List_DoesNotExist' => ListDoesNotExistError,
'List_InvalidInterestFieldType' => ListInvalidInterestFieldTypeError,
'List_InvalidOption' => ListInvalidOptionError,
'List_InvalidUnsubMember' => ListInvalidUnsubMemberError,
'List_InvalidBounceMember' => ListInvalidBounceMemberError,
'List_AlreadySubscribed' => ListAlreadySubscribedError,
'List_NotSubscribed' => ListNotSubscribedError,
'List_InvalidImport' => ListInvalidImportError,
'MC_PastedList_Duplicate' => MCPastedListDuplicateError,
'MC_PastedList_InvalidImport' => MCPastedListInvalidImportError,
'Email_AlreadySubscribed' => EmailAlreadySubscribedError,
'Email_AlreadyUnsubscribed' => EmailAlreadyUnsubscribedError,
'Email_NotExists' => EmailNotExistsError,
'Email_NotSubscribed' => EmailNotSubscribedError,
'List_MergeFieldRequired' => ListMergeFieldRequiredError,
'List_CannotRemoveEmailMerge' => ListCannotRemoveEmailMergeError,
'List_Merge_InvalidMergeID' => ListMergeInvalidMergeIDError,
'List_TooManyMergeFields' => ListTooManyMergeFieldsError,
'List_InvalidMergeField' => ListInvalidMergeFieldError,
'List_InvalidInterestGroup' => ListInvalidInterestGroupError,
'List_TooManyInterestGroups' => ListTooManyInterestGroupsError,
'Campaign_DoesNotExist' => CampaignDoesNotExistError,
'Campaign_StatsNotAvailable' => CampaignStatsNotAvailableError,
'Campaign_InvalidAbsplit' => CampaignInvalidAbsplitError,
'Campaign_InvalidContent' => CampaignInvalidContentError,
'Campaign_InvalidOption' => CampaignInvalidOptionError,
'Campaign_InvalidStatus' => CampaignInvalidStatusError,
'Campaign_NotSaved' => CampaignNotSavedError,
'Campaign_InvalidSegment' => CampaignInvalidSegmentError,
'Campaign_InvalidRss' => CampaignInvalidRssError,
'Campaign_InvalidAuto' => CampaignInvalidAutoError,
'MC_ContentImport_InvalidArchive' => MCContentImportInvalidArchiveError,
'Campaign_BounceMissing' => CampaignBounceMissingError,
'Campaign_InvalidTemplate' => CampaignInvalidTemplateError,
'Invalid_EcommOrder' => InvalidEcommOrderError,
'Absplit_UnknownError' => AbsplitUnknownError,
'Absplit_UnknownSplitTest' => AbsplitUnknownSplitTestError,
'Absplit_UnknownTestType' => AbsplitUnknownTestTypeError,
'Absplit_UnknownWaitUnit' => AbsplitUnknownWaitUnitError,
'Absplit_UnknownWinnerType' => AbsplitUnknownWinnerTypeError,
'Absplit_WinnerNotSelected' => AbsplitWinnerNotSelectedError,
'Invalid_Analytics' => InvalidAnalyticsError,
'Invalid_DateTime' => InvalidDateTimeError,
'Invalid_Email' => InvalidEmailError,
'Invalid_SendType' => InvalidSendTypeError,
'Invalid_Template' => InvalidTemplateError,
'Invalid_TrackingOptions' => InvalidTrackingOptionsError,
'Invalid_Options' => InvalidOptionsError,
'Invalid_Folder' => InvalidFolderError,
'Invalid_URL' => InvalidURLError,
'Module_Unknown' => ModuleUnknownError,
'MonthlyPlan_Unknown' => MonthlyPlanUnknownError,
'Order_TypeUnknown' => OrderTypeUnknownError,
'Invalid_PagingLimit' => InvalidPagingLimitError,
'Invalid_PagingStart' => InvalidPagingStartError,
'Max_Size_Reached' => MaxSizeReachedError,
'MC_SearchException' => MCSearchExceptionError
}
begin
error_info = JSON.parse(body)
if error_info['status'] != 'error' or not error_info['name']
raise Error, "We received an unexpected error: #{body}"
end
if error_map[error_info['name']]
raise error_map[error_info['name']], error_info['error']
else
raise Error, error_info['error']
end
rescue JSON::ParserError
raise Error, "We received an unexpected error: #{body}"
end
end
|