Cloud-CV / Cloud-CV/evalai-cli

Keyerror on logging errors when found in making a call to api

Open
#313 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
57
Forks
70
PR merge metrics
No merged PRs in 30d

Description

When an error is received while making a request to the backend, we catch it, and if it is present in the EVALAI_ERROR_CODES, we log it using the lines:
```
if response.status_code in EVALAI_ERROR_CODES:
validate_token(response.json())
echo(
style(
"\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.\n".format(response.json()["error"]),
fg="red",
bold=True,
)
)
```
But response.json() does not have the key `error` in cases. For e.g., I made a request using an expired token and got an error. So when I logged the entire json.response(), it was something like
```
{'detail': 'Given token not valid for any token type', 'code': 'token_not_valid', 'messages': [{'token_class': 'RefreshToken', 'token_type': 'refresh', 'message': 'Token is invalid or expired'}]}
```
This does not contains a key named error

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.