Skip to content

Commit

Permalink
make sure response is not None before calling repsonse.headers to avo…
Browse files Browse the repository at this point in the history
…id AttributeError (#392)

Thanks for the fix @JannisNe .
  • Loading branch information
JannisNe authored Jan 5, 2023
1 parent 2ada636 commit 5c443c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pyvo/dal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ def from_except(cls, exc, url=None):
except AttributeError:
response = None
code = 0
message = str(exc)

# if there is a response, refine the error message
if response is not None:
code = response.status_code
message = str(exc)
content_type = response.headers.get('content-type', None)
if content_type and 'text/plain' in content_type:
message = '{} for {}'.format(response.text, url)
content_type = response.headers.get('content-type', None)
if content_type and 'text/plain' in content_type:
message = '{} for {}'.format(response.text, url)

# TODO votable handling

return DALServiceError(message, code, exc, url)
Expand Down

0 comments on commit 5c443c5

Please sign in to comment.