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 response body for errors #193

Open
praseodym opened this issue Jul 11, 2023 · 3 comments
Open

Return response body for errors #193

praseodym opened this issue Jul 11, 2023 · 3 comments

Comments

@praseodym
Copy link

When the Shodan HTTP API returns an error status code, such as 403 Forbidden, this library will only return a APIError object.

However, the HTTP response will usually also include data in the response body, such as {"error": "Requires membership or higher to access"}. This data is currently ignored and not available through the library.

It would be useful if this response body is also made available by the library, for example to show a more informative error message to the end user.

@achillean
Copy link
Owner

You should be able to access the specific error message from the APIException.value property

@praseodym
Copy link
Author

The contents of the APIException.value property are hardcoded in the library, so e.g. for status code 403 the error message will always be Access denied (403 Forbidden):

elif data.status_code == 403:
raise APIError('Access denied (403 Forbidden)')
elif data.status_code == 502:
raise APIError('Bad Gateway (502)')

For some status codes, the Shodan response body will contain more detailed information that is useful to have and return to the end user.

@achillean
Copy link
Owner

I think that's because for some of those responses the body isn't JSON but you're right, we should use the JSON error message if available as that is typically more precise.

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

2 participants