XEP-0363: Use a specific exception for HTTP errors

This commit is contained in:
Emmanuel Gil Peyrot 2018-11-20 07:44:09 +01:00
parent 4699861925
commit 33370e42f1

View file

@ -30,6 +30,10 @@ class UploadServiceNotFound(FileUploadError):
class FileTooBig(FileUploadError): class FileTooBig(FileUploadError):
pass pass
class HTTPError(FileUploadError):
def __str__(self):
return 'Could not upload file: %d (%s)' % (self.args[0], self.args[1])
class XEP_0363(BasePlugin): class XEP_0363(BasePlugin):
''' This plugin only supports Python 3.5+ ''' ''' This plugin only supports Python 3.5+ '''
@ -149,7 +153,7 @@ class XEP_0363(BasePlugin):
headers=headers, headers=headers,
timeout=timeout) timeout=timeout)
if response.status >= 400: if response.status >= 400:
raise FileUploadError("could not upload file: %d (%s)" % (response.status, await response.text())) raise HTTPError(response.status, await response.text())
log.info('Response code: %d (%s)', response.status, await response.text()) log.info('Response code: %d (%s)', response.status, await response.text())
response.close() response.close()
return slot['get']['url'] return slot['get']['url']