Mercurial > libervia-backend
diff sat/plugins/plugin_sec_aesgcm.py @ 3186:84b0c8b4dee0
plugin download, aesgcm: fixed handling of HTTP errors
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Feb 2020 15:54:43 +0100 |
parents | 98b321234068 |
children | adf1aeaa0d37 |
line wrap: on
line diff
--- a/sat/plugins/plugin_sec_aesgcm.py Wed Feb 26 15:54:43 2020 +0100 +++ b/sat/plugins/plugin_sec_aesgcm.py Wed Feb 26 15:54:43 2020 +0100 @@ -19,15 +19,15 @@ import re from textwrap import dedent from functools import partial -from urllib.parse import urlparse +from urllib import parse import mimetypes import secrets from cryptography.hazmat.primitives import ciphers from cryptography.hazmat.primitives.ciphers import modes from cryptography.hazmat import backends from cryptography.exceptions import AlreadyFinalized -from urllib import parse import treq +from twisted.internet import defer from sat.core.i18n import _ from sat.core.constants import Const as C from sat.core import exceptions @@ -108,11 +108,15 @@ progress_id = file_obj.uid resp = await treq.get(download_url, unbuffered=True) - d = treq.collect(resp, partial( - self.onDataDownload, - client=client, - file_obj=file_obj, - decryptor=decryptor)) + if resp.code == 200: + d = treq.collect(resp, partial( + self.onDataDownload, + client=client, + file_obj=file_obj, + decryptor=decryptor)) + else: + d = defer.Deferred() + self.host.plugins["DOWNLOAD"].errbackDownload(file_obj, d, resp) return progress_id, d def onDataDownload(self, data, client, file_obj, decryptor): @@ -226,7 +230,7 @@ mess_encrypted = client.encryption.isEncrypted(data) attachments = data['extra'].setdefault(C.MESS_KEY_ATTACHMENTS, []) for link in links: - path = urlparse(link).path + path = parse.urlparse(link).path attachment = { "url": link, }