From 9e14fde11e05ef93f516a3d908676fd4cb358f53 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 21 Jan 2022 04:36:58 +0000 Subject: [PATCH] Improve photo upload error handling --- apiserver/apiserver/api/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index c0f0a1c..c3ce89d 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -11,7 +11,7 @@ from rest_framework.views import exception_handler from dateutil import relativedelta from uuid import uuid4 from PIL import Image, ImageDraw, ImageFont, ImageOps, JpegImagePlugin -#JpegImagePlugin._getmp = lambda x: None +JpegImagePlugin._getmp = lambda x: None from bleach.sanitizer import Cleaner from PyPDF2 import PdfFileWriter, PdfFileReader from reportlab.pdfgen import canvas @@ -180,7 +180,7 @@ def process_image_upload(upload, crop): try: pic = Image.open(upload) except OSError: - raise serializers.ValidationError(dict(photo='Invalid image file.')) + raise serializers.ValidationError(dict(non_field_errors='Invalid image file.')) logging.info('Detected format: %s', pic.format) @@ -189,7 +189,7 @@ def process_image_upload(upload, crop): elif pic.format == 'JPEG': ext = '.jpg' else: - raise serializers.ValidationError(dict(photo='Image must be a jpg or png.')) + raise serializers.ValidationError(dict(non_field_errors='Image must be a jpg or png.')) pic = ImageOps.exif_transpose(pic)