Skip to content

Commit

Permalink
🐛 fix empty text and add debugging messages for pydantic model valida…
Browse files Browse the repository at this point in the history
…tions (#18)

alert.attachments[].text can be None :(

Ticket: APPSRE-10541
  • Loading branch information
chassing authored Jul 9, 2024
1 parent 1fbb4db commit c1ef37f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions glitchtip_jira_bridge/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
APIRouter,
Depends,
FastAPI,
Request,
status,
)
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from prometheus_fastapi_instrumentator import Instrumentator

from .api import router
Expand Down Expand Up @@ -45,6 +49,17 @@ def create_app() -> FastAPI:
async def _startup() -> None:
instrumentator.expose(fast_api_app, include_in_schema=False)

@fast_api_app.exception_handler(RequestValidationError)
async def validation_exception_handler(
request: Request, exc: RequestValidationError
) -> JSONResponse:
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ")
logging.error(f"{request}: {exc_str}")
content = {"status_code": 422, "message": exc_str, "data": None}
return JSONResponse(
content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY
)

return fast_api_app


Expand Down
2 changes: 1 addition & 1 deletion glitchtip_jira_bridge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Field(BaseModel):
class Attachment(BaseModel):
title: str
title_link: str
text: str
text: str | None
image_url: str | None = None
color: str | None = None
fields: list[Field] | None = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ branch = true
omit = ["*/tests/*"]

[tool.coverage.report]
fail_under = 95
fail_under = 90

# Ruff configuration
[tool.ruff]
Expand Down

0 comments on commit c1ef37f

Please sign in to comment.