-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a kwik_exception_handler to format and handle custom appli…
…cation exceptions derived from KwikException
- Loading branch information
1 parent
7f09d48
commit 4bbed32
Showing
3 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from .base import KwikException, DuplicatedEntity, Forbidden, NotFound | ||
from __future__ import annotations | ||
|
||
from .base import DuplicatedEntity, Forbidden, KwikException, NotFound | ||
from .exporters import ExporterLimitExceeded | ||
from .users import UserInactive, IncorrectCredentials, UserNotFound | ||
from .handler import kwik_exception_handler | ||
from .users import IncorrectCredentials, UserInactive, UserNotFound |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from fastapi import Request | ||
from kwik.exceptions import KwikException | ||
from starlette.responses import JSONResponse | ||
|
||
|
||
async def kwik_exception_handler(request: Request, exc: KwikException): | ||
return JSONResponse( | ||
status_code=exc.status_code, | ||
content={"detail": exc.detail}, | ||
) |