Skip to content

Commit e5437b2

Browse files
PietroConvalleADpietro convalle
andauthored
Bench 121 rfc787 standard messages (#24)
* added drf-problems dependency * fixes middleware 404, temporarly in the codebase, awaiting for the PR to be merged, fixes error codes using drf-problems * replaced Responses to Raise Exception * temporarly changed dependencies to forks, awaiting for merge * Defined generic Exception Class * Renamed integrityHandlerMixin * added detail handle for serializer Errors * Added detail handle for 404 errors * added typing_extensions to dependencies * added specific type ignore Co-authored-by: pietro convalle <pietroconvalle@python.it>
1 parent 76cf77f commit e5437b2

21 files changed

Lines changed: 710 additions & 351 deletions

answerking/settings/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Django base settings for answerking project.
33
"""
44
import os
5-
65
from pathlib import Path
6+
77
from corsheaders.defaults import default_headers, default_methods
88

9+
from answerking_app.utils.json404_middleware_config import json404_response
10+
911
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1012
BASE_DIR = Path(__file__).resolve().parent.parent
1113

@@ -35,6 +37,7 @@
3537
"answerking_app.apps.AnswerkingAppConfig",
3638
"rest_framework",
3739
"corsheaders",
40+
"drf_problems",
3841
]
3942

4043
MIDDLEWARE = [
@@ -72,7 +75,8 @@
7275
REST_FRAMEWORK = {
7376
"DEFAULT_PARSER_CLASSES": [
7477
"rest_framework.parsers.JSONParser",
75-
]
78+
],
79+
"EXCEPTION_HANDLER": "drf_problems.exceptions.exception_handler",
7680
}
7781

7882
# Database
@@ -107,6 +111,8 @@
107111
},
108112
]
109113

114+
# JSON404 middleware
115+
JSON404_DATA_FUNCTION = json404_response
110116
# Internationalization
111117
# https://docs.djangoproject.com/en/4.0/topics/i18n/
112118

answerking/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
path("api/", include("answerking_app.urls.category_urls")),
88
path("api/", include("answerking_app.urls.order_urls")),
99
path("admin/", admin.site.urls),
10+
path("", include("drf_problems.urls")),
1011
]
1112

1213
if settings.DEBUG:

answerking_app/models/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def create(self, validated_data: dict) -> Order:
151151
)
152152
for order_item in order_items_data:
153153
item_data: ItemType = order_item.pop("item")
154-
item: Item = get_object_or_404(Item, pk=item_data["id"])
154+
item: Item = get_object_or_404(Item, pk=item_data["id"]) # type: ignore[reportTypedDictNotRequiredAccess]
155155
if item.retired:
156156
continue
157157
OrderLine.objects.create(order=order, item=item, **order_item)

0 commit comments

Comments
 (0)