Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Invalid handling of exceptions different from ValidationError #1140

Open
Labels
@floels

Description

@floels

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:

  1. Start a new Django project. Install and set up:

with all standard settings.

  1. Create a minimalistic app with only one URL pattern pointing to Simple JWT'sTokenRefreshView:
fromdjango.urlsimportpathfromrest_framework_simplejwt.viewsimportTokenRefreshViewurlpatterns= [path("token/refresh/",TokenRefreshView.as_view(),name=("token_refresh")),]
  1. Add a basic test to check the response of this view when a wrong refresh token is provided:
fromdjango.testimportTestCaseclassAuthenticationTests(TestCase):deftest_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)
  1. Debug and inspectresponse.json() at the end of the test:

Capture d’écran 2023-03-16 à 17 58 08

See that theerrors attribute contains two redundant items:

Capture d’écran 2023-03-16 à 19 42 23

Checklist

  • Certain that this is a bug (if unsure or you have a question usediscussions instead)
  • Code snippet or unit test added to reproduce bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp