|
26 | 26 | """ |
27 | 27 |
|
28 | 28 | import json |
29 | | -from typing import Any, Awaitable, Callable, List, Optional |
| 29 | +from typing import Any, Awaitable, Callable |
30 | 30 |
|
31 | 31 | try: |
32 | 32 | from django.http import HttpRequest, JsonResponse |
33 | 33 | from django.views import View |
34 | 34 | except ModuleNotFoundError as e: # pragma: no cover |
35 | | - raise ImportError( |
36 | | - "Django integration requires 'django'. " |
37 | | - "Install it with: uv add fastapi_api_key[django]" |
38 | | - ) from e |
| 35 | + raise ImportError("Django integration requires 'django'. Install it with: uv add fastapi_api_key[django]") from e |
39 | 36 |
|
40 | 37 | from pydantic import ValidationError |
41 | 38 |
|
|
45 | 42 | ApiKeyCountOut, |
46 | 43 | ApiKeyCreateIn, |
47 | 44 | ApiKeyCreatedOut, |
48 | | - ApiKeyOut, |
49 | 45 | ApiKeySearchIn, |
50 | 46 | ApiKeySearchOut, |
51 | 47 | ApiKeyUpdateIn, |
@@ -109,7 +105,7 @@ async def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Any |
109 | 105 | return await super().dispatch(request, *args, **kwargs) |
110 | 106 | except _HttpError as exc: |
111 | 107 | return _error(exc.status, exc.detail) |
112 | | - except KeyNotFound as exc: |
| 108 | + except KeyNotFound: |
113 | 109 | return _error(404, "API key not found") |
114 | 110 |
|
115 | 111 | http_method_names = ["get", "post", "patch", "delete", "head", "options"] |
@@ -301,7 +297,7 @@ async def post(self, request: HttpRequest) -> JsonResponse: |
301 | 297 | api_key=payload.api_key, |
302 | 298 | required_scopes=payload.required_scopes, |
303 | 299 | ) |
304 | | - except (InvalidKey, KeyNotFound) as exc: |
| 300 | + except (InvalidKey, KeyNotFound): |
305 | 301 | return _error(401, "API key invalid") |
306 | 302 | except KeyNotProvided: |
307 | 303 | return _error(401, "API key missing") |
|
0 commit comments