Skip to content

Commit

Permalink
Improve error responses
Browse files Browse the repository at this point in the history
Send back error logs in utf-8 encoded strings.
This helps in displaying logs properly in frontend.

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Jun 11, 2024
1 parent 129b5e9 commit 5527aa0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/teuthology_api/routes/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async def create_run(
except HTTPError as http_err:
log.error(http_err)
raise HTTPException(
status_code=http_err.response.status_code, detail=repr(http_err)
status_code=http_err.response.status_code, detail=str(http_err, "utf-8")
) from http_err
except Exception as err:
log.error(err)
raise HTTPException(status_code=500, detail=repr(err)) from err
raise HTTPException(status_code=500, detail=str(err, "utf-8")) from err
4 changes: 2 additions & 2 deletions src/teuthology_api/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def get_run_details(run_name: str):
except HTTPError as http_err:
log.error(http_err)
raise HTTPException(
status_code=http_err.response.status_code, detail=repr(http_err)
status_code=http_err.response.status_code, detail=str(http_err, "utf-8")
) from http_err
except Exception as err:
log.error(err)
raise HTTPException(status_code=500, detail=repr(err)) from err
raise HTTPException(status_code=500, detail=str(err, "utf-8")) from err


def get_username(request: Request):
Expand Down
2 changes: 1 addition & 1 deletion src/teuthology_api/services/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ async def run(args, send_logs: bool, token: dict, request: Request):
return {"kill": "success"}
except Exception as exc:
log.error("teuthology-kill command failed with the error: %s", repr(exc))
raise HTTPException(status_code=500, detail=repr(exc)) from exc
raise HTTPException(status_code=500, detail=str(exc, "utf-8")) from exc
2 changes: 1 addition & 1 deletion src/teuthology_api/services/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def run(args, send_logs: bool, access_token: str):
return {"run": run_details}
except Exception as exc:
log.error("teuthology.suite.main failed with the error: %s", repr(exc))
raise HTTPException(status_code=500, detail=repr(exc)) from exc
raise HTTPException(status_code=500, detail=str(exc, "utf-8")) from exc


def make_run_name(run_dic):
Expand Down

0 comments on commit 5527aa0

Please sign in to comment.