Skip to content

Commit

Permalink
feat: adds ImproperConfig to exception handler (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin authored Jul 28, 2024
1 parent 6cc15b5 commit efa3c39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions litestar_vite/inertia/exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from litestar.connection.base import AuthT, StateT, UserT
from litestar.exceptions import (
HTTPException,
ImproperlyConfiguredException,
InternalServerException,
NotAuthorizedException,
NotFoundException,
Expand Down Expand Up @@ -72,7 +73,7 @@ def create_inertia_exception_response(request: Request[UserT, AuthT, StateT], ex
content.update({"extra": extras})
try:
flash(request, detail, category="error")
except AttributeError:
except (AttributeError, ImproperlyConfiguredException):
msg = "Unable to set `flash` session state. A valid session was not found for this request."
request.logger.warning(msg)
if extras and len(extras) >= 1:
Expand All @@ -82,11 +83,8 @@ def create_inertia_exception_response(request: Request[UserT, AuthT, StateT], ex
match = FIELD_ERR_RE.search(error_detail)
field = match.group(1) if match else default_field
if isinstance(message, dict):
error(request, field, error_detail)
if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST} or isinstance(
exc,
PermissionDeniedException,
):
error(request, field, error_detail if error_detail else detail)
if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST}:
return InertiaBack(request)
if isinstance(exc, PermissionDeniedException):
return InertiaBack(request)
Expand Down
6 changes: 3 additions & 3 deletions litestar_vite/inertia/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def share(
) -> None:
try:
connection.session.setdefault("_shared", {}).update({key: value})
except AttributeError:
except (AttributeError, ImproperlyConfiguredException):
msg = "Unable to set `share` session state. A valid session was not found for this request."
connection.logger.warning(msg)

Expand All @@ -60,7 +60,7 @@ def error(
) -> None:
try:
connection.session.setdefault("_errors", {}).update({key: message})
except AttributeError:
except (AttributeError, ImproperlyConfiguredException):
msg = "Unable to set `error` session state. A valid session was not found for this request."
connection.logger.warning(msg)

Expand All @@ -87,7 +87,7 @@ def get_shared_props(request: ASGIConnection[Any, Any, Any, Any]) -> Dict[str, A
if session_prop not in props and session_prop in request.session:
props[session_prop] = request.session.get(session_prop)

except AttributeError:
except (AttributeError, ImproperlyConfiguredException):
msg = "Unable to generate all shared props. A valid session was not found for this request."
request.logger.warning(msg)
props["flash"] = flash
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ license = { text = "MIT" }
name = "litestar-vite"
readme = "README.md"
requires-python = ">=3.8"
version = "0.2.6"
version = "0.2.7"

[project.urls]
Changelog = "https://cofin.github.io/litestar-vite/latest/changelog"
Expand Down

0 comments on commit efa3c39

Please sign in to comment.