404 Error class not returning
The intended result from receiving a 404 using Octokit.rb appears to be to return a simple error class of:
Octokit::NotFound which inherits from ClientError.
However in version 4.20.0 this is not the case. Instead it returns NilClass and throws a stack trace.
It would be nice to get proper error handling working so that I have something to work with and not just have to use a rescue block around an API call just to avoid logging out a somewhat useless 404 error message and commensurate stack trace. An error class that contains the error code and message at minimum would be far more useful.
However in version
4.20.0this is not the case. Instead it returns NilClass and throws a stack trace.
@AHaymond is this something new for 4.20? Or it's just that this is true for 4.20?
@tarebyte true for 4.20, I have not tried another version.
Here is an example output. This is just raising an unrecoverable error instead of handing me the 404 class as designed.
As you can see I am running on Ruby 2.7.2 for this project.
2.7.2 | main:0 > git.client.ref(git.repo_name, "heads/release-2021-02-04")
GET https://api.github.com/repos/AHaymond/github_prs/git/refs/heads/release-2021-02-04: 404 - Not Found // See: https://docs.github.com/enterprise/2.18/user/rest/reference/git#get-a-reference
/Users/.rvm/gems/ruby-2.7.2@tools/gems/octokit-4.20.0/lib/octokit/response/raise_error.rb:14:in `on_complete'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/middleware.rb:19:in `block in call'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/response.rb:59:in `on_complete'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/middleware.rb:18:in `call'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/octokit-4.20.0/lib/octokit/middleware/follow_redirects.rb:73:in `perform_with_redirection'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/octokit-4.20.0/lib/octokit/middleware/follow_redirects.rb:61:in `call'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/request/retry.rb:148:in `call'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/rack_builder.rb:154:in `build_response'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/connection.rb:492:in `run_request'
/Users/.rvm/gems/ruby-2.7.2@tools/gems/faraday-1.3.0/lib/faraday/connection.rb:198:in `get'
It would be preferable just to have a falsey value or an empty array returned on a 404 rather than an exception being thrown. This would be much more useful than an exception being thrown.
👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!