forked from mirrors/bookwyrm
Adds error logging to status views
This commit is contained in:
parent
23c6019340
commit
007751c8cb
2 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue