Exemplo n.º 1
0
    def specific_api_error(self, rbody, rcode, resp, rheaders, error_data):
        util.log_info(
            'Ping++ API error received',
            error_code=error_data.get('code'),
            error_type=error_data.get('type'),
            error_message=error_data.get('message'),
            error_param=error_data.get('param'),
        )

        if rcode in [400, 404]:
            raise error.InvalidRequestError(error_data.get('message'),
                                            error_data.get('param'),
                                            error_data.get('code'), rbody,
                                            rcode, resp, rheaders)
        elif rcode == 401:
            raise error.AuthenticationError(error_data.get('message'), rbody,
                                            rcode, resp, rheaders)
        elif rcode == 402:
            raise error.ChannelError(error_data.get('message'),
                                     error_data.get('param'),
                                     error_data.get('code'), rbody, rcode,
                                     resp, rheaders)
        elif rcode == 403:
            raise error.RateLimitError(error_data.get('message'), rbody, rcode,
                                       resp, rheaders)
        else:
            raise error.APIError(error_data.get('message'), rbody, rcode, resp,
                                 rheaders)
Exemplo n.º 2
0
    def handle_api_error(self, rbody, rcode, resp):
        try:
            err = resp['error']
        except (KeyError, TypeError):
            raise error.APIError(
                "Invalid response object from API: %r (HTTP response code "
                "was %d)" % (rbody, rcode), rbody, rcode, resp)

        if rcode in [400, 404]:
            raise error.InvalidRequestError(err.get('message'),
                                            err.get('param'), rbody, rcode,
                                            resp)
        elif rcode == 401:
            raise error.AuthenticationError(err.get('message'), rbody, rcode,
                                            resp)
        elif rcode == 402:
            raise error.ChannelError(err.get('message'), err.get('param'),
                                     err.get('code'), rbody, rcode, resp)
        else:
            raise error.APIError(err.get('message'), rbody, rcode, resp)