Skip to content

Commit

Permalink
pg8000 type error / add stacktrace for std handler (#3048)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolyachevets authored Sep 26, 2024
1 parent bfbd4c2 commit 2eacef9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions auth-api/src/auth_api/exceptions/exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def db_handler(self, error): # pylint: disable=useless-option-value
"""Handle Database error."""
stack_trace = traceback.format_exc()
message_text = str(error.__dict__["orig"]) if "orig" in error.__dict__ else "Internal server error"
error_message = f"[{{error: {message_text}}}, {{stack_trace: {stack_trace}}}]"
error_message = f"{{error: {message_text}, stack_trace: {stack_trace}}}"
logger.exception(error_message)
error_text = error.__dict__["code"] if hasattr(error.__dict__, "code") else ""
status_code = error.status_code if hasattr(error, "status_code") else 500
Expand All @@ -51,10 +51,12 @@ def db_handler(self, error): # pylint: disable=useless-option-value
def std_handler(self, error): # pylint: disable=useless-option-value
"""Handle standard exception."""
if isinstance(error, HTTPException):
logger.error(f"[{{Error occurred: {error.code}}}, {{Path: {request.path}}}]")
logger.error(f"{{error code: {error.code}, path: {request.path}}}")
message = dict(message=error.description, path=request.path)
else:
logger.exception(error)
stack_trace = traceback.format_exc()
error_message = f"{{error: {error}, stack_trace: {stack_trace}}}"
logger.exception(error_message)
message = dict(message="Internal server error")

return message, error.code if isinstance(error, HTTPException) else 500, RESPONSE_HEADERS
Expand Down
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def remove_membership_for_staff(cls, user_id: int):
def find_membership_by_user_and_org(cls, user_id: int, org_id: int) -> Membership:
"""Get the membership for the specified user and org."""
records = (
cls.query.filter(cls.user_id == user_id)
.filter(cls.org_id == org_id)
cls.query.filter(cls.user_id == int(user_id or -1))
.filter(cls.org_id == int(org_id or -1))
.filter(cls.status.in_(VALID_STATUSES))
.order_by(desc(Membership.created))
.first()
Expand Down

0 comments on commit 2eacef9

Please sign in to comment.