Handle empty shortpixel
This commit is contained in:
parent
6db67d9420
commit
0e1d84733e
1 changed files with 8 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
@ -16,6 +17,8 @@ from PIL import Image
|
|||
|
||||
from articles.utils import build_full_absolute_url
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AbsoluteUrlFieldFile(FieldFile):
|
||||
def get_full_absolute_url(self, request: WSGIRequest) -> str:
|
||||
|
@ -95,7 +98,12 @@ class Attachment(models.Model):
|
|||
files={self.original_file.name: original_file},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
res = response.json()
|
||||
if len(res) == 0:
|
||||
logger.error("Shortpixel response is empty: %s", res)
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
res_data = res[0]
|
||||
|
||||
# Loop until it's done
|
||||
|
|
Reference in a new issue