plugin download, aesgcm: fixed handling of HTTP errors

This commit is contained in:
Goffi 2020-02-26 15:54:43 +01:00
commit c16dd25fc9

View file

@ -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 @@ class AESGCM(object):
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 @@ class AESGCM(object):
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,
}