Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle stream api connection errors gracefully (#1636)
Closes #1559 Thanks to @Ankush-Chander (cherry picked from commit 4ab30b9)
- Loading branch information
1 parent
3e6344a
commit a106ec4
Showing
6 changed files
with
36 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .api_responses import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from starlette.responses import JSONResponse, StreamingResponse | ||
from starlette.types import Send | ||
|
||
from rubrix.server.errors import APIErrorHandler | ||
|
||
|
||
class StreamingResponseWithErrorHandling(StreamingResponse): | ||
|
||
async def stream_response(self, send: Send) -> None: | ||
try: | ||
return await super().stream_response(send) | ||
except Exception as ex: | ||
json_response: JSONResponse = await APIErrorHandler.common_exception_handler(send, error=ex) | ||
await send({"type": "http.response.body", "body": json_response.body, "more_body": False}) |