Return retryable event response when Gitea request fails #68
10
src/main.py
10
src/main.py
|
|
@ -124,3 +124,13 @@ async def event_stream():
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
return JSONResponse(
|
||||||
|
{"error": "Gitea event stream is temporarily unavailable"},
|
||||||
|
status_code=503,
|
||||||
|
headers={
|
||||||
|
"Retry-After": str(
|
||||||
|
max(1, math.ceil(EVENT_STREAM_TIMEOUT_SECONDS))
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,22 @@ async def test_event_stream_returns_retryable_response_when_gitea_exceeds_deadli
|
||||||
assert cancelled.is_set()
|
assert cancelled.is_set()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_event_stream_returns_retryable_response_when_gitea_request_fails(monkeypatch):
|
||||||
|
async def failing_activity_events():
|
||||||
|
raise ConnectionError("connection refused")
|
||||||
|
|
||||||
|
monkeypatch.setattr(main, "activity_events", failing_activity_events)
|
||||||
|
|
||||||
|
response = await main.event_stream()
|
||||||
|
|
||||||
|
assert response.status_code == 503
|
||||||
|
assert response.headers["retry-after"] == "5"
|
||||||
|
assert json.loads(response.body) == {
|
||||||
|
"error": "Gitea event stream is temporarily unavailable"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_activity_events_fetches_feed_for_authenticated_user(monkeypatch):
|
async def test_activity_events_fetches_feed_for_authenticated_user(monkeypatch):
|
||||||
paths = []
|
paths = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user