Skip to content

Commit

Permalink
chore: add sentry logs to json_api (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng authored Mar 1, 2024
1 parent feb79fd commit 75b1754
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/seer/json_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
from typing import Any, Callable, List, Tuple, Type, TypeVar, get_type_hints

import sentry_sdk
from flask import Flask, request
from pydantic import BaseModel, ValidationError
from werkzeug.exceptions import BadRequest
Expand Down Expand Up @@ -29,11 +30,13 @@ def decorator(implementation: _F) -> _F:
def wrapper() -> Any:
data = request.get_json()
if not isinstance(data, dict):
sentry_sdk.capture_message(f"Data is not an object: {type(data)}")
raise BadRequest("Data is not an object")

try:
result: BaseModel = implementation(request_annotation.model_validate(data))
except ValidationError as e:
sentry_sdk.capture_exception(e)
raise BadRequest(str(e))

return result.model_dump()
Expand Down

0 comments on commit 75b1754

Please sign in to comment.