Skip to content

Commit 5527aa0

Browse files
committed
Improve error responses
Send back error logs in utf-8 encoded strings. This helps in displaying logs properly in frontend. Signed-off-by: Vallari Agrawal <[email protected]>
1 parent 129b5e9 commit 5527aa0

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Diff for: src/teuthology_api/routes/kill.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ async def create_run(
3737
except HTTPError as http_err:
3838
log.error(http_err)
3939
raise HTTPException(
40-
status_code=http_err.response.status_code, detail=repr(http_err)
40+
status_code=http_err.response.status_code, detail=str(http_err, "utf-8")
4141
) from http_err
4242
except Exception as err:
4343
log.error(err)
44-
raise HTTPException(status_code=500, detail=repr(err)) from err
44+
raise HTTPException(status_code=500, detail=str(err, "utf-8")) from err

Diff for: src/teuthology_api/services/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def get_run_details(run_name: str):
6363
except HTTPError as http_err:
6464
log.error(http_err)
6565
raise HTTPException(
66-
status_code=http_err.response.status_code, detail=repr(http_err)
66+
status_code=http_err.response.status_code, detail=str(http_err, "utf-8")
6767
) from http_err
6868
except Exception as err:
6969
log.error(err)
70-
raise HTTPException(status_code=500, detail=repr(err)) from err
70+
raise HTTPException(status_code=500, detail=str(err, "utf-8")) from err
7171

7272

7373
def get_username(request: Request):

Diff for: src/teuthology_api/services/kill.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ async def run(args, send_logs: bool, token: dict, request: Request):
6767
return {"kill": "success"}
6868
except Exception as exc:
6969
log.error("teuthology-kill command failed with the error: %s", repr(exc))
70-
raise HTTPException(status_code=500, detail=repr(exc)) from exc
70+
raise HTTPException(status_code=500, detail=str(exc, "utf-8")) from exc

Diff for: src/teuthology_api/services/suite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def run(args, send_logs: bool, access_token: str):
4343
return {"run": run_details}
4444
except Exception as exc:
4545
log.error("teuthology.suite.main failed with the error: %s", repr(exc))
46-
raise HTTPException(status_code=500, detail=repr(exc)) from exc
46+
raise HTTPException(status_code=500, detail=str(exc, "utf-8")) from exc
4747

4848

4949
def make_run_name(run_dic):

0 commit comments

Comments
 (0)