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

separate error for network failure would be nice #176

Open
matkoniecz opened this issue Oct 8, 2024 · 3 comments · May be fixed by #178
Open

separate error for network failure would be nice #176

matkoniecz opened this issue Oct 8, 2024 · 3 comments · May be fixed by #178

Comments

@matkoniecz
Copy link
Contributor

basically another aspect of #115 #135

It would be nice to have easy way of distinguishing network failures from other issues.

And yes, recovery is dependent on context - as maybe edit was done and maybe was not done. But ability do detect what happened and being to able to catch specifically network failures would be great.

Currently I would need to catch all osmapi.errors.ApiError, cast them to string and try to detect signature comments while hoping for no false positives.

  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 649, in WayUpdate
    return self._do("modify", "way", WayData)
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 1825, in _do
    return self._do_manu(action, OsmType, OsmData)
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/OsmApi.py", line 1861, in _do_manu
    result = self._session._put(
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/http.py", line 154, in _put
    return self._http("PUT", path, True, data, return_value=return_value)
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/http.py", line 109, in _http
    return self._http_request(
  File "/home/mateusz/.local/lib/python3.10/site-packages/osmapi/http.py", line 81, in _http_request
    raise errors.ApiError(0, str(e), "")
osmapi.errors.ApiError: Request failed: 0 - ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) - 
@metaodi
Copy link
Owner

metaodi commented Oct 8, 2024

I see, I'm wondering if there is an easy way to wrap the existing errors (i.e. expose the underlying RequestException to be able to inspect it) or simpls create new exception in this library to cover all? / most? cases. What do you think?

@metaodi
Copy link
Owner

metaodi commented Oct 8, 2024

Just read about the "raise Exception(...) from e" pattern, which seems to be a good idea when wrapping exceptions to pass the original exception to the caller.

So maybe I'll add this to all "wrapped exceptions" while still adding the most common errors as it's own exception class.

@matkoniecz
Copy link
Contributor Author

If I would implement this I would catch multitude of network exceptions, throw new OsmapiNetworkException or similar.

Maybe include original as a field in a new exception?

No idea is it a good design.

@metaodi metaodi linked a pull request Oct 13, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants