Пример #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 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))
Пример #3
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))