|
17 | 17 | import json
|
18 | 18 | import re
|
19 | 19 |
|
| 20 | +import requests |
20 | 21 | import six
|
21 | 22 | from six.moves import urllib
|
22 | 23 |
|
@@ -215,22 +216,63 @@ def auth_error_code(self):
|
215 | 216 |
|
216 | 217 | _ERROR_CODE_MAPPINGS = {
|
217 | 218 | 'CLAIMS_TOO_LARGE': exceptions.INVALID_ARGUMENT,
|
| 219 | + 'INVALID_CONTINUE_URL': exceptions.INVALID_ARGUMENT, |
| 220 | + 'INVALID_DYNAMIC_LINK_DOMAIN': exceptions.INVALID_ARGUMENT, |
| 221 | + 'FORBIDDEN_CLAIM': exceptions.INVALID_ARGUMENT, |
| 222 | + 'INVALID_CLAIMS': exceptions.INVALID_ARGUMENT, |
| 223 | + 'INVALID_DURATION': exceptions.INVALID_ARGUMENT, |
218 | 224 | 'INVALID_EMAIL': exceptions.INVALID_ARGUMENT,
|
| 225 | + 'INVALID_ID_TOKEN': exceptions.INVALID_ARGUMENT, |
| 226 | + 'INVALID_PAGE_SELECTION': exceptions.INVALID_ARGUMENT, |
| 227 | + 'INVALID_PHONE_NUMBER': exceptions.INVALID_ARGUMENT, |
| 228 | + 'MISSING_ANDROID_PACKAGE_NAME': exceptions.INVALID_ARGUMENT, |
| 229 | + 'MISSING_IOS_BUNDLE_ID': exceptions.INVALID_ARGUMENT, |
| 230 | + 'MISSING_LOCAL_ID': exceptions.INVALID_ARGUMENT, |
| 231 | + 'MISSING_USER_ACCOUNT': exceptions.INVALID_ARGUMENT, |
| 232 | + 'UNAUTHORIZED_DOMAIN': exceptions.INVALID_ARGUMENT, |
| 233 | + 'WEAK_PASSWORD': exceptions.INVALID_ARGUMENT, |
| 234 | + |
219 | 235 | 'INSUFFICIENT_PERMISSION': exceptions.PERMISSION_DENIED,
|
220 | 236 | 'OPERATION_NOT_ALLOWED': exceptions.PERMISSION_DENIED,
|
221 | 237 | 'PERMISSION_DENIED': exceptions.PERMISSION_DENIED,
|
| 238 | + |
| 239 | + 'CONFIGURATION_NOT_FOUND': exceptions.NOT_FOUND, |
| 240 | + 'PROJECT_NOT_FOUND': exceptions.NOT_FOUND, |
222 | 241 | 'USER_NOT_FOUND': exceptions.NOT_FOUND,
|
223 |
| - 'DUPLICATE_LOCAL_ID': exceptions.ALREADY_EXISTS, |
| 242 | + |
224 | 243 | 'DUPLICATE_EMAIL': exceptions.ALREADY_EXISTS,
|
| 244 | + 'DUPLICATE_LOCAL_ID': exceptions.ALREADY_EXISTS, |
| 245 | + 'EMAIL_EXISTS': exceptions.ALREADY_EXISTS, |
225 | 246 | }
|
226 | 247 |
|
227 | 248 |
|
228 | 249 | def handle_http_error(msg, error):
|
229 |
| - response_payload = {} |
230 |
| - if error.response is not None: |
231 |
| - response_payload = error.response.json() |
232 |
| - msg += '\n Server response: {0}'.format(error.response.content.decode()) |
233 |
| - server_code = response_payload.get('error', {}).get('message') |
234 |
| - canonical_code = _ERROR_CODE_MAPPINGS.get(server_code, exceptions.UNKNOWN) |
| 250 | + """Creates and raises a FirebaseAuthError from a requests exception.""" |
| 251 | + if isinstance(error, requests.exceptions.Timeout): |
| 252 | + raise FirebaseAuthError( |
| 253 | + exceptions.DEADLINE_EXCEEDED, |
| 254 | + '{0}; Timed out while making an API call: {1}'.format(msg, error), |
| 255 | + cause=error) |
| 256 | + elif isinstance(error, requests.exceptions.ConnectionError): |
| 257 | + raise FirebaseAuthError( |
| 258 | + exceptions.UNAVAILABLE, |
| 259 | + '{0}; Network or service unavailable: {1}'.format(msg, error), |
| 260 | + cause=error) |
| 261 | + elif error.response is None: |
| 262 | + raise FirebaseAuthError( |
| 263 | + exceptions.UNKNOWN, |
| 264 | + '{0}; Unknown error while making remote service call: {1}'.format(msg, error), |
| 265 | + cause=error) |
| 266 | + |
| 267 | + server_code, canonical_code = _get_error_codes(error) |
| 268 | + msg += '\n Server response: {0}'.format(error.response.content.decode()) |
235 | 269 | raise FirebaseAuthError(
|
236 | 270 | canonical_code, msg, cause=error, http_response=error.response, auth_error_code=server_code)
|
| 271 | + |
| 272 | +def _get_error_codes(error): |
| 273 | + response_payload = error.response.json() |
| 274 | + error_obj = response_payload.get('error', {}) |
| 275 | + server_code = None |
| 276 | + if isinstance(error_obj, dict): |
| 277 | + server_code = error_obj.get('message') |
| 278 | + return server_code, _ERROR_CODE_MAPPINGS.get(server_code, exceptions.UNKNOWN) |
0 commit comments