From 8647b06ca251984f846ba071472958b5ce3181ca Mon Sep 17 00:00:00 2001 From: Aliaksei Paulouski Date: Wed, 12 Jun 2019 16:41:08 +0200 Subject: [PATCH] Add TooManyRequests error --- src/galaxy/api/errors.py | 6 +++++- src/galaxy/http.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/galaxy/api/errors.py b/src/galaxy/api/errors.py index 189db00..5a23002 100644 --- a/src/galaxy/api/errors.py +++ b/src/galaxy/api/errors.py @@ -22,6 +22,10 @@ class UnknownBackendResponse(ApplicationError): def __init__(self, data=None): super().__init__(4, "Backend responded in uknown way", data) +class TooManyRequests(ApplicationError): + def __init__(self, data=None): + super().__init__(5, "Too many requests. Try again later", data) + class InvalidCredentials(ApplicationError): def __init__(self, data=None): super().__init__(100, "Invalid credentials", data) @@ -80,4 +84,4 @@ class MessageNotFound(ApplicationError): class ImportInProgress(ApplicationError): def __init__(self, data=None): - super().__init__(600, "Import already in progress", data) \ No newline at end of file + super().__init__(600, "Import already in progress", data) diff --git a/src/galaxy/http.py b/src/galaxy/http.py index 5b494ca..0e7b8b2 100644 --- a/src/galaxy/http.py +++ b/src/galaxy/http.py @@ -6,10 +6,11 @@ import aiohttp import certifi from galaxy.api.errors import ( - AccessDenied, AuthenticationRequired, - BackendTimeout, BackendNotAvailable, BackendError, NetworkError, UnknownBackendResponse, UnknownError + AccessDenied, AuthenticationRequired, BackendTimeout, BackendNotAvailable, BackendError, NetworkError, + TooManyRequests, UnknownBackendResponse, UnknownError ) + class HttpClient: def __init__(self, limit=20, timeout=aiohttp.ClientTimeout(total=60), cookie_jar=None): ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) @@ -39,6 +40,8 @@ class HttpClient: raise AccessDenied() if response.status == HTTPStatus.SERVICE_UNAVAILABLE: raise BackendNotAvailable() + if response.status == HTTPStatus.TOO_MANY_REQUESTS: + raise TooManyRequests() if response.status >= 500: raise BackendError() if response.status >= 400: