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

Return error description functionality #138

Open
skaina00 opened this issue Jun 3, 2022 · 2 comments
Open

Return error description functionality #138

skaina00 opened this issue Jun 3, 2022 · 2 comments

Comments

@skaina00
Copy link

skaina00 commented Jun 3, 2022

Hey guys,

Do you know if is possible get the error message in Python instead a generic error message?

If yes, please let me know. If not, could be a good solution to help troubleshooting.

Expected error output:
Error: Branch feature/test-api-github2 not found
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\ghapi\core.py", line 63, in call
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "C:\Users\victo\AppData\Roaming\Python\Python310\site-packages\ghapi\core.py", line 112, in call
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True,
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\fastcore\net.py", line 212, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\fastcore\net.py", line 113, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None

Current the error output:
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\ghapi\core.py", line 63, in call
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "C:\Users\victo\AppData\Roaming\Python\Python310\site-packages\ghapi\core.py", line 112, in call
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True,
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\fastcore\net.py", line 212, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\fastcore\net.py", line 113, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None

@Lawouach
Copy link

Ping indeed. This is not really ideal to not know.

Maybe, remove the from None to prevent making the original exception silent?

@myahl-uncomn
Copy link

I know this is old, but for anyone who lands here, you can catch the HTTPError exception (from urllib.error import HTTPError) or the more specific errors like HTTP4xxClientError or HTTP404NotFoundError (from fastcore.net import HTTP4xxClientError, HTTP404NotFoundError). Your type checker may not like the specific ones like HTTP401UnauthorizedError, HTTP404NotFoundError, etc. but they are legit.
e.g.

from fastcore.net import HTTP401UnauthorizedError
from ghapi.all import GhApi

api = GhApi(owner='foo', repo='bar', key='bad key')
try:
    res = api.get_branch('my_branch')
except HTTP401UnauthorizedError as e:
    print(e.reason)

Unauthorized
====Error Body====
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest"
}

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

No branches or pull requests

3 participants