-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ConnectionError handler #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,10 @@ def make_request(self, url: Optional[str] = None) -> Response: | |
) | ||
except TooManyRedirects: | ||
raise HTTPException(status_code=404, detail=f"Not found for url: {url}") | ||
except ConnectionError: | ||
raise HTTPException(status_code=500, detail=f"Connection error for url: {url}") | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=f"Error for url: {url}. {e}") | ||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching a generic Consider logging the exception before raising the |
||
if 400 <= response.status_code < 500: | ||
raise HTTPException( | ||
status_code=response.status_code, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching
ConnectionError
and raising anHTTPException
with a 500 status code is not entirely appropriate. AConnectionError
typically indicates a problem with the network connection, which might be more accurately represented by a 503 Service Unavailable status code, as it suggests the service is temporarily unavailable.Committable suggestion