Skip to content

Commit cd3b446

Browse files
authored
Merge pull request #136 from eadwinCode/sync_auth_error
fix(AuthError): Sync authentication error with Ninja
2 parents 428c220 + 58e7667 commit cd3b446

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ninja_extra/operation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from django.http.response import HttpResponse, HttpResponseBase
2121
from django.utils.encoding import force_str
2222
from ninja.constants import NOT_SET
23+
from ninja.errors import AuthenticationError
2324
from ninja.operation import (
2425
AsyncOperation as NinjaAsyncOperation,
2526
)
@@ -245,7 +246,8 @@ async def _run_authentication(self, request: HttpRequest) -> Optional[HttpRespon
245246
if result:
246247
request.auth = result # type: ignore
247248
return None
248-
return self.api.create_response(request, {"detail": "Unauthorized"}, status=401)
249+
250+
return self.api.on_exception(request, AuthenticationError())
249251

250252
@asynccontextmanager
251253
async def _prep_run( # type:ignore

0 commit comments

Comments
 (0)