Skip to content

Commit f5f1c53

Browse files
committed
Update README.md
1 parent 7c9de48 commit f5f1c53

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

README.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99

1010
A library for [Django Rest Framework](https://www.django-rest-framework.org/) returning **consistent, predictable and easy-to-parse API error messages**.
1111

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, but it still serves as a way to include errors in a predictable and easy-to-parse format for any API consumer. Error messages are formatted using RFC7807 keywords and DRF exception data.
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+
Error messages are formatted using RFC7807 keywords and DRF exception data.
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.
1316

1417
## What's different?
1518

1619
Compared to other similar and popular libraries, this library:
1720

1821
- Is based on RFC7807 guidelines
1922
- Aims to provide not only a standardized format for error details, but also human-readable error messages (perfect for both internal and public APIs)
20-
- Transforms both `django.core.exceptions.ValidationError` and `rest_framework.errors.ValidationError` to API errors, so you don't have to handle error raised by services/domain logic, `clean()`, or other functions/methods
23+
- Transforms both `django.core.exceptions.ValidationError` and `rest_framework.errors.ValidationError` to API errors, so you don't have to handle error raised by services/domain logic, `clean()`, etc.
2124

2225
## Table of Contents
2326

@@ -57,13 +60,13 @@ REST_FRAMEWORK = {
5760

5861
### Error structure overview
5962

60-
API error messages typically include the following keys:
63+
API error messages will include the following keys:
6164

62-
- `"title"` (`str`): A brief summary that describes the problem type
63-
- `"detail"` (`list[str] | None`): A list of specific explanations related to the problem
64-
- `"invalid_params"` (`list[dict] | None`): A list of dict containing details about parameters that were invalid or malformed in the request. Each dict within this list provides:
65-
- `"name"` (`str`): The name of the parameter that was found to be invalid
66-
- `"reasons"` (`list[str]`): A list of strings describing the specific reasons why the parameter was considered invalid or malformed
65+
- `"title"` (`str`): A brief summary that describes the problem type.
66+
- `"detail"` (`list[str] | None`): A list of specific explanations related to the problem, if any.
67+
- `"invalid_params"` (`list[dict] | None`): A list of dict containing details about parameters that were invalid or malformed in the request, if any. Each dict within this list provides:
68+
- `"name"` (`str`): The name of the parameter that was found to be invalid.
69+
- `"reasons"` (`list[str]`): A list of strings describing the specific reasons why the parameter was considered invalid or malformed.
6770

6871
```json
6972
{
@@ -91,17 +94,18 @@ API error messages typically include the following keys:
9194

9295
```json
9396
{
94-
"title": "Error message.",
95-
"invalid_params": [
96-
{
97-
"name": "field_name",
98-
"reason": [
99-
"error",
100-
...
101-
]
102-
},
103-
...
104-
]
97+
"title": "Error message.",
98+
"details": null,
99+
"invalid_params": [
100+
{
101+
"name": "field_name",
102+
"reason": [
103+
"error"
104+
// ...
105+
]
106+
}
107+
// ...
108+
]
105109
}
106110
```
107111

@@ -111,17 +115,20 @@ API error messages typically include the following keys:
111115
{
112116
"title": "Error message.",
113117
"detail": [
114-
"error",
115-
...
116-
]
118+
"error"
119+
// ...
120+
],
121+
"invalid_params": null
117122
}
118123
```
119124

120125
#### Other bad requests with no detail
121126

122127
```json
123128
{
124-
"title": "Error message."
129+
"title": "Error message.",
130+
"detail": null,
131+
"invalid_params": null
125132
}
126133
```
127134

@@ -146,15 +153,16 @@ If `CAMELIZE` is set to `True`:
146153
```json
147154
{
148155
"title": "Error message.",
156+
"details": null,
149157
"invalidParams": [
150158
{
151159
"name": "fieldName",
152160
"reason": [
153-
"error",
154-
...
161+
"error"
162+
// ...
155163
]
156164
}
157-
...
165+
// ...
158166
]
159167
}
160168
```
@@ -274,13 +282,19 @@ All the necessary commands are included in the `Makefile`.
274282

275283
We are using `tox` and `poetry` to run tests in every supported Python version.
276284

277-
Run test with the commands below:
285+
Run test during development with the commands below:
278286

279287
```
280-
make install
288+
make install # only if necessary
281289
make test
282290
```
283291

292+
Finally, run `tox` to ensure the changes work for every supported python version:
293+
294+
```
295+
tox -v
296+
```
297+
284298
## Support
285299

286300
Please [open an issue](https://github.com/gripep/drf-simple-api-errors/issues/new).

0 commit comments

Comments
 (0)