Open
Description
Description of the Bug Report
The current error handling assumes that each field in the error exception dictionary is a field name. This is only true for ValidationException though but not for other exception such as InvalidToken as in example below.
Error handling needs to be adjusted so ValidationException and other errors are handled different.
Orginal report
To reproduce:
- Start a new Django project. Install and set up:
- Django Rest Framework,
- DRF Simple JWT,
- Django REST framework JSON:API.
with all standard settings.
- Create a minimalistic app with only one URL pattern pointing to Simple JWT's
TokenRefreshView
:from django.urls import path from rest_framework_simplejwt.views import TokenRefreshView urlpatterns = [ path("token/refresh/", TokenRefreshView.as_view(), name=("token_refresh")), ]
- Add a basic test to check the response of this view when a wrong refresh token is provided:
from django.test import TestCase class AuthenticationTests(TestCase): def test_refresh_jw_token_wrong_refresh(self): """ Ensure we don't obtain a refreshed JWT when providing a wrong refresh token. """ response = self.client.post( "/myapp/token/refresh/", {"refresh": "wrong.refreshToken"}, format="json" ) self.assertEqual(response.status_code, 401)
- Debug and inspect
response.json()
at the end of the test:See that the
errors
attribute contains two redundant items:
Checklist
- Certain that this is a bug (if unsure or you have a question use discussions instead)
- Code snippet or unit test added to reproduce bug