def specific_api_error(self, rbody, rcode, resp, rheaders, error_data): util.log_info( 'Stripe 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'), ) # Rate limits were previously coded as 400's with code 'rate_limit' if rcode == 429 or (rcode == 400 and error_data.get('code') == 'rate_limit'): return error.RateLimitError(error_data.get('message'), rbody, rcode, resp, rheaders) elif rcode in [400, 404]: return error.InvalidRequestError(error_data.get('message'), error_data.get('param'), rbody, rcode, resp, rheaders) elif rcode == 401: return error.AuthenticationError(error_data.get('message'), rbody, rcode, resp, rheaders) elif rcode == 402: return error.CardError(error_data.get('message'), error_data.get('param'), error_data.get('code'), rbody, rcode, resp, rheaders) elif rcode == 403: return error.PermissionError(error_data.get('message'), rbody, rcode, resp, rheaders) else: return error.APIError(error_data.get('message'), rbody, rcode, resp, rheaders)
def instance_url(self): token = util.utf8(self.id) extn = urllib.parse.quote_plus(token) if hasattr(self, 'customer'): customer = util.utf8(self.customer) base = Customer.class_url() owner_extn = urllib.parse.quote_plus(customer) class_base = "sources" elif hasattr(self, 'recipient'): recipient = util.utf8(self.recipient) base = Recipient.class_url() owner_extn = urllib.parse.quote_plus(recipient) class_base = "cards" elif hasattr(self, 'account'): account = util.utf8(self.account) base = Account.class_url() owner_extn = urllib.parse.quote_plus(account) class_base = "external_accounts" else: raise error.InvalidRequestError( "Could not determine whether card_id %s is " "attached to a customer, recipient, or " "account." % token, 'id') return "%s/%s/%s/%s" % (base, owner_extn, class_base, extn)
def handle_api_error(self, rbody, rcode, resp, rheaders): 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) # Rate limits were previously coded as 400's with code 'rate_limit' if rcode == 429 or (rcode == 400 and err.get('code') == 'rate_limit'): raise error.RateLimitError( err.get('message'), rbody, rcode, resp, rheaders) elif rcode in [400, 404]: raise error.InvalidRequestError( err.get('message'), err.get('param'), rbody, rcode, resp, rheaders) elif rcode == 401: raise error.AuthenticationError( err.get('message'), rbody, rcode, resp, rheaders) elif rcode == 402: raise error.CardError(err.get('message'), err.get('param'), err.get('code'), rbody, rcode, resp, rheaders) elif rcode == 403: raise error.PermissionError( err.get('message'), rbody, rcode, resp, rheaders) else: raise error.APIError(err.get('message'), rbody, rcode, resp, rheaders)
def instance_url(self): id = self.get('id') if not id: raise error.InvalidRequestError( 'Could not determine which URL to request: %s instance ' 'has invalid ID: %r' % (type(self).__name__, id), 'id') id = util.utf8(id) base = self.class_url() extn = urllib.parse.quote_plus(id) return "%s/%s" % (base, extn)
def instance_url(self): id = self.get('id') if not isinstance(id, str): raise error.InvalidRequestError( 'Could not determine which URL to request: %s instance ' 'has invalid ID: %r, %s. ID should be of type `str` (or' ' `unicode`)' % (type(self).__name__, id, type(id)), 'id') id = util.utf8(id) base = self.class_url() extn = urllib.parse.quote_plus(id) return "%s/%s" % (base, extn)
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.CardError(err.get('message'), err.get('param'), err.get('code'), rbody, rcode, resp) else: raise error.APIError(err.get('message'), rbody, rcode, resp)
def instance_url(self): self.id = util.utf8(self.id) extn = urllib.parse.quote_plus(self.id) if (hasattr(self, 'customer')): self.customer = util.utf8(self.customer) base = Customer.class_url() owner_extn = urllib.parse.quote_plus(self.customer) elif (hasattr(self, 'recipient')): self.recipient = util.utf8(self.recipient) base = Recipient.class_url() owner_extn = urllib.parse.quote_plus(self.recipient) else: raise error.InvalidRequestError( "Could not determine whether card_id %s is " "attached to a customer " "or a recipient." % self.id, 'id') return "%s/%s/cards/%s" % (base, owner_extn, extn)