mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-02-12 01:20:51 +03:00
Rename ExceptionHandlerMixin
to ApiErrorsMixin
This commit is contained in:
parent
ca0728a8fe
commit
55e135436d
|
@ -593,7 +593,7 @@ def get_error_message(exc):
|
||||||
|
|
||||||
You can move this code to a mixin and use it in every API to prevent code duplication.
|
You can move this code to a mixin and use it in every API to prevent code duplication.
|
||||||
|
|
||||||
We call this `ExceptionHandlerMixin`. Here's a sample implementation from one of our projects:
|
We call this `ApiErrorsMixin`. Here's a sample implementation from one of our projects:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from rest_framework import exceptions as rest_exceptions
|
from rest_framework import exceptions as rest_exceptions
|
||||||
|
@ -603,7 +603,7 @@ from django.core.exceptions import ValidationError
|
||||||
from project.common.utils import get_error_message
|
from project.common.utils import get_error_message
|
||||||
|
|
||||||
|
|
||||||
class ExceptionHandlerMixin:
|
class ApiErrorsMixin:
|
||||||
"""
|
"""
|
||||||
Mixin that transforms Django and Python exceptions into rest_framework ones.
|
Mixin that transforms Django and Python exceptions into rest_framework ones.
|
||||||
Without the mixin, they return 500 status code which is not desired.
|
Without the mixin, they return 500 status code which is not desired.
|
||||||
|
@ -629,7 +629,7 @@ Having this mixin in mind, our API can be written like that:
|
||||||
```python
|
```python
|
||||||
class CourseCreateApi(
|
class CourseCreateApi(
|
||||||
SomeAuthenticationMixin,
|
SomeAuthenticationMixin,
|
||||||
ExceptionHandlerMixin,
|
ApiErrorsMixin,
|
||||||
APIView
|
APIView
|
||||||
):
|
):
|
||||||
class InputSerializer(serializers.Serializer):
|
class InputSerializer(serializers.Serializer):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user