Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/app/core/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def knowhere_exception_handler(
# responses and ``WWW-Authenticate`` for authentication challenges.
headers = dict(response_headers or {})
headers["X-Request-ID"] = request_id
retry_after = exc.details.get("retry_after")
retry_after = (exc.details or {}).get("retry_after")
if retry_after:
headers["Retry-After"] = str(retry_after)

Expand Down
36 changes: 36 additions & 0 deletions apps/api/tests/contract/test_exception_handlers_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ async def query_retrieval() -> dict[str, bool]:
return app


def _create_invalid_webhook_app() -> FastAPI:
_prepare_api_app_imports()

from app.core.exception_handlers import setup_exception_handlers
from shared.core.exceptions.webhook_exceptions import WebhookConfigException

app = FastAPI()

@app.post("/v2/jobs")
async def create_job() -> dict[str, bool]:
raise WebhookConfigException(
user_message="Invalid webhook URL",
internal_message=(
"Webhook validation failed: Hostname localhost failed validation"
),
)

setup_exception_handlers(app)
return app


async def test_invalid_webhook_config_returns_client_error() -> None:
app = _create_invalid_webhook_app()
transport = ASGITransport(app=app)

async with AsyncClient(transport=transport, base_url="http://test") as client:
response = await client.post("/v2/jobs")

assert response.status_code == 400
response_json = cast(dict[str, object], response.json())
error = cast(dict[str, object], response_json["error"])
assert response_json["success"] is False
assert error["code"] == "INVALID_ARGUMENT"
assert error["message"] == "Invalid webhook URL"


async def test_get_to_post_only_route_returns_method_not_allowed() -> None:
app = _create_post_only_app()
transport = ASGITransport(app=app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def __init__(
internal_message=internal_message,
user_message=user_message,
http_status_code=400,
details=details,
)
self.details = details


class WebhookDeliveryException(WebhookException):
Expand Down
Loading