Пример #1
0
    def raise_exception_for_graphql_error(response):
        if "errors" not in response:
            return

        for error in response["errors"]:
            if "extensions" in error and "errorClass" in error["extensions"]:
                error_type = error["extensions"]["errorClass"]
                if error_type == "VALIDATION":
                    continue
                elif error_type == "AUTHENTICATION":
                    raise AuthenticationError(error["message"])
                elif error_type == "AUTHORIZATION":
                    raise AuthorizationError(error["message"])
                elif error_type == "NOT_FOUND":
                    raise NotFoundError
                elif error_type == "UNSUPPORTED_CLIENT":
                    raise UpgradeRequiredError("Please upgrade your client library.")
                elif error_type == "RESOURCE_LIMIT":
                    raise TooManyRequestsError
                elif error_type == "INTERNAL":
                    raise ServerError
                elif error_type == "SERVICE_AVAILABILITY":
                    raise DownForMaintenanceError
                else:
                    raise UnexpectedError("Unexpected Response: " + error["message"])
Пример #2
0
 def __init__(self, query, results, method):
     if "search_results" not in results:
         raise UnexpectedError(
             "Unprocessable entity due to an invalid request")
     self.__ids = results["search_results"]["ids"]
     self.__method = method
     self.__page_size = results["search_results"]["page_size"]
     self.__query = query
Пример #3
0
 def handle_exception(self, exception):
     if isinstance(exception, requests.exceptions.ConnectionError):
         raise ConnectionError(exception)
     elif isinstance(exception, requests.exceptions.HTTPError):
         raise InvalidResponseError(exception)
     elif isinstance(exception, requests.exceptions.Timeout):
         raise TimeoutError(exception)
     else:
         raise UnexpectedError(exception)
Пример #4
0
 def raise_exception_from_status(status, message=None):
     if status == 401:
         raise AuthenticationError()
     elif status == 403:
         raise AuthorizationError(message)
     elif status == 404:
         raise NotFoundError()
     elif status == 426:
         raise UpgradeRequiredError()
     elif status == 500:
         raise ServerError()
     elif status == 503:
         raise DownForMaintenanceError()
     else:
         raise UnexpectedError("Unexpected HTTP_RESPONSE " + str(status))
Пример #5
0
 def raise_exception_from_status(status, message=None):
     if status == 401:
         raise AuthenticationError()
     elif status == 403:
         raise AuthorizationError(message)
     elif status == 404:
         raise NotFoundError()
     elif status == 408:
         raise RequestTimeoutError()
     elif status == 426:
         raise UpgradeRequiredError()
     elif status == 429:
         raise TooManyRequestsError()
     elif status == 500:
         raise ServerError()
     elif status == 503:
         raise ServiceUnavailableError()
     elif status == 504:
         raise GatewayTimeoutError()
     else:
         raise UnexpectedError("Unexpected HTTP_RESPONSE " + str(status))