Skip to content

Commit

Permalink
fix(API): error handling to not cover 404 with a 500
Browse files Browse the repository at this point in the history
  • Loading branch information
janaka committed Sep 17, 2024
1 parent eeb6745 commit dc9fca5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "docq"
version = "0.13.7"
version = "0.13.8"
description = "Docq.AI - Your private ChatGPT alternative. Securely unlock knowledge from confidential documents."
authors = ["Docq.AI Team <[email protected]>"]
maintainers = ["Docq.AI Team <[email protected]>"]
Expand Down
2 changes: 2 additions & 0 deletions web/api/rag_completion_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def post(self: Self) -> None:
except ValueError as e:
logging.error("ValueError:", e)
raise HTTPError(400, reason=f"Bad request. {e}", log_message=str(e)) from e
except HTTPError as e:
raise e
except Exception as e:
logging.error("Exception:", e)
raise HTTPError(500, reason="Internal server error", log_message=str(e)) from e
4 changes: 4 additions & 0 deletions web/api/spaces_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def get(self: Self) -> None:

spaces_response_model = SpacesResponseModel(response=space_model_list)
self.write(spaces_response_model.model_dump(by_alias=True))
except ValidationError as e:
raise HTTPError(400, reason="Bad request") from e
except HTTPError as e:
raise e
except Exception as e:
logging.error("Error: ", e)
raise HTTPError(500, reason="Internal server error", log_message=f"Error: {str(e)}") from e
Expand Down
7 changes: 7 additions & 0 deletions web/api/threads_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def get(self: Self, feature_: FEATURE, thread_id: int) -> None:

except ValidationError as e:
raise HTTPError(status_code=400, reason="Bad request", log_message=str(e)) from e
except HTTPError as e:
raise e
except Exception as e:
raise HTTPError(status_code=500, reason="Internal server error", log_message=str(e)) from e

@authenticated
def delete(self: Self, feature_: FEATURE, thread_id: str) -> None:
Expand Down Expand Up @@ -171,6 +175,7 @@ def get(self: Self, feature_: FEATURE, thread_id: str) -> None:

try:
thread = rq.list_thread_history(feature, int(thread_id))

if not len(thread) > 0:
raise HTTPError(status_code=404, reason="Thread not found")

Expand All @@ -187,6 +192,8 @@ def get(self: Self, feature_: FEATURE, thread_id: str) -> None:
except ValidationError as e:
print("ValidationError: ", e)
raise HTTPError(status_code=400, reason="Invalid page or limit") from e
except HTTPError as e:
raise e
except Exception as e:
raise HTTPError(status_code=500, reason="Internal server error") from e

Expand Down

0 comments on commit dc9fca5

Please sign in to comment.