diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py index 3cd153d2..2aa9136d 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -1,4 +1,5 @@ """ the good stuff! the books! """ +import logging from django.contrib.auth.decorators import login_required from django.core.cache import cache from django.db import transaction @@ -15,6 +16,8 @@ from .status import CreateStatus from .helpers import get_edition, handle_reading_status, is_api_request from .helpers import load_date_in_user_tz_as_utc +logger = logging.getLogger(__name__) + # pylint: disable=no-self-use # pylint: disable=too-many-return-statements @@ -36,6 +39,7 @@ class ReadingStatus(View): # redirect if we're already on this shelf return TemplateResponse(request, f"reading_progress/{template}", {"book": book}) + @transaction.atomic def post(self, request, status, book_id): """Change the state of a book by shelving it and adding reading dates""" identifier = { @@ -45,6 +49,7 @@ class ReadingStatus(View): "stop": models.Shelf.STOPPED_READING, }.get(status) if not identifier: + logger.exception("Invalid reading status type: %s", status) return HttpResponseBadRequest() # invalidate related caches diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index af15064f..670ea571 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -1,5 +1,6 @@ """ what are we here for if not for posting """ import re +import logging from urllib.parse import urlparse from django.contrib.auth.decorators import login_required @@ -21,6 +22,8 @@ from bookwyrm.utils import regex from .helpers import handle_remote_webfinger, is_api_request from .helpers import load_date_in_user_tz_as_utc +logger = logging.getLogger(__name__) + # pylint: disable= no-self-use @method_decorator(login_required, name="dispatch") @@ -72,11 +75,14 @@ class CreateStatus(View): form = getattr(forms, f"{status_type}Form")( request.POST, instance=existing_status ) - except AttributeError: + except AttributeError as err: + logger.exception(err) return HttpResponseBadRequest() + if not form.is_valid(): if is_api_request(request): - return HttpResponse(status=500) + logger.exception(form.errors) + return HttpResponseBadRequest() return redirect(request.headers.get("Referer", "/")) status = form.save(commit=False)