Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
burnerlee opened this issue Jan 26, 2021 · 8 comments · May be fixed by #320
Open

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

burnerlee opened this issue Jan 26, 2021 · 8 comments · May be fixed by #320

Comments

@burnerlee
Copy link
Contributor

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

@phiyodr
Copy link

phiyodr commented Feb 23, 2021

Hi @burnerlee, I run in the same error as you. I'm using a fresh install of v1.3.12.

@Ram81
Copy link
Member

Ram81 commented Feb 23, 2021

@burnerlee nice catch, this error response is from jwt token API that we added recently. If you are interested you can pick this issue and send a PR to fix it.

@burnerlee
Copy link
Contributor Author

@Ram81 yeah sure, I'll make a PR for this

@burnerlee
Copy link
Contributor Author

@Ram81, should I do something like, checking if error key is present in the response, if it does, use the same value, if it doesn't then use the detail key for getting the error?

@Ram81
Copy link
Member

Ram81 commented Feb 28, 2021

@burnerlee yes

@burnerlee
Copy link
Contributor Author

Oh okay, it is only this jwt error log which causes this error, or there may be some other errors too? Which need to be handled 😅

@Ram81
Copy link
Member

Ram81 commented Feb 28, 2021

For now its just the JWT API which has a different error response format. Rest of our APIs are already handled

@burnerlee
Copy link
Contributor Author

thank you so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants