-
Notifications
You must be signed in to change notification settings - Fork 7
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
Handle errors thrown by Faraday and Curb and re-raise a PDC:Error #20
Comments
Added it to JIRA (PDC-1835) for future plan. |
Seems there already has a PDC:Error class, so no need to do the changes? |
@xiangge yes, see the code in the bug report. begin
PDC::V1::Release.find(release_id)
rescue Curl::Err::HostResolutionError, Faraday::ConnectionFailed
# handle it ...
rescue PDC::TokenFetchFailed
# handle it ...
rescue Curl::Err::CurlError => e
# handle it ...
end We want to replace the whole error handling with begin
PDC::V1::Release.find(release_id)
rescue PDC::Error => e
# handle it ...
end the Faraday ruby gem has a nice way of doing this see: https://github.com/lostisland/faraday/blob/master/lib/faraday/error.rb |
Looking into that, thanks :) |
@sthaha after we add the Faraday::ConnectionFailed with the PDC::Error.const_set, we still can't catch the errors with PDC:Error, we just can catch it with PDC::Error::ConnectionFailed I have one question, why people need to write codes like that.
|
@xiangge if you look into Faradays implementation closely, you would find that it has a way to
So the idea is to catch errors generated by Say you want to replace Faraday with something better or Curl with something else, now the client code will have to change according to our implmentation, instead if we wrapped all errors as PDC::Error or sub-class, then the client code will only have to handle the PDC::Errors HTH |
In order to allow clients to handle all errors raised within PDC, lets provide a superclass PDC::Error than can be caught instead of having to understand the internals of pdc.
e.g.
The client must be able to handle it as
The text was updated successfully, but these errors were encountered: