You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,27 +16,29 @@ Changes:
16
16
17
17
Changes:
18
18
19
-
- Add docstrings to handlers
19
+
- Add docstrings
20
20
- Improve Makefile
21
21
- Improve README
22
22
23
23
## [1.0.3] - 2025-03-16
24
24
25
25
Changes:
26
26
27
-
- Update README
28
-
- Improve tests
29
27
- Fix DRF API settings initialization
28
+
- Improve tests
29
+
- Update README
30
30
31
31
## [2.0.0] - 2025-07-11
32
32
33
33
Breaking changes:
34
34
35
-
- The API error response now always includes the keys: `title`, `detail`, and `invalid_param`. The `title` key is always populated, while `detail` and `invalid_param` may be `null` depending on the error source.
35
+
- The API error response now **always** includes the keys: `title`, `detail`, and `invalid_param`. The `title` key is always populated, while `detail` and `invalid_param` may be `null` depending on the error source.
Copy file name to clipboardExpand all lines: README.md
+7-73Lines changed: 7 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ A library for [Django Rest Framework](https://www.django-rest-framework.org/) re
12
12
This library was built with [RFC7807](https://tools.ietf.org/html/rfc7807) guidelines in mind, but with a small twist: it defines a "problem detail" as a list instead of a string, but it still serves as a way to include errors in a human-readable and easy-to-parse format for any API consumer.
13
13
Error messages are formatted using RFC7807 keywords and DRF exception data.
14
14
15
-
This library always returns errors in a consistent, predictable structure, making them easier to handle and parse, unlike standard DRF, where error response formats vary depending on the error source.
15
+
Unlike standard DRF, where the error response format varies depending on the error source, this library always returns errors in a consistent, predictable structure to make them easier to handle and parse.
16
16
17
17
## What's different?
18
18
@@ -134,7 +134,7 @@ API error messages will include the following keys:
134
134
135
135
## Settings
136
136
137
-
Default available settings:
137
+
Default settings:
138
138
139
139
```python
140
140
DRF_SIMPLE_API_ERRORS= {
@@ -171,89 +171,23 @@ If `CAMELIZE` is set to `True`:
171
171
172
172
Support for exceptions that differ from the standard structure of the Django Rest Framework.
173
173
174
-
For instance, you may want to specify you own exception:
174
+
For example, if you need to customize how a specific exception is handled or want to format an existing exception differently, you can create your own handler.
You can handle this by creating a `handlers.py` file and specifying an handler for your use case:
232
-
233
-
```python
234
-
defhandle_exc_custom_authentication_failed(exc):
235
-
from path.to.my.exceptions import AuthenticationFailed
236
-
237
-
ifisinstance(exc, AuthenticationFailed):
238
-
try:
239
-
exc.detail = exc.detail["messages"][0]["message"]
240
-
except (KeyError, IndexError):
241
-
exc.detail = exc.detail["detail"]
242
-
243
-
return exc
244
-
```
176
+
To customize error handling for your project, simply create a new file (for example, `extra_handlers.py`) and define your own handler functions. This approach lets you tailor error responses to fit your specific needs.
245
177
246
178
Then add it to the `EXTRA_HANDLERS` list in this package settings:
0 commit comments