nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
36 stars 32 forks source link

Add status code to RequestError #230

Closed TitouanS31 closed 3 weeks ago

TitouanS31 commented 3 weeks ago

I would like to add a way to retrieve the status code from RequestError to handle these exceptions differently, depending on their status. As a concrete example, I want to silently catch some 504 errors, since they do not seem to be a real problem (cf. #23).

joewesch commented 3 weeks ago

You should be able to get the error information from the exception that is raised:

try:
    # make call
except RequestError as foo:
    status_code = foo.req.status_code
TitouanS31 commented 3 weeks ago

Thank you, I did not see the req attribute.