Skip to content

Commit 1968f23

Browse files
committed
Change service error class method to resolve conflict in reference to issue piotrmurach#273
1 parent 7804bff commit 1968f23

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

lib/github_api/error/service_error.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ def self.http_status_code(code)
2121
# @return [Hash[Integer, Object]]
2222
#
2323
# @api public
24-
def self.errors
25-
@errors ||= Hash[
26-
descendants.map { |klass| [klass.new({}).http_status_code, klass] }
24+
def self.error_mapping
25+
@error_mapping ||= Hash[
26+
descendants.map do |klass|
27+
[klass.new({}).http_status_code, klass]
28+
end
2729
]
2830
end
2931

lib/github_api/response/raise_error.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
module Github
77
class Response::RaiseError < Faraday::Response::Middleware
8-
8+
# Check if status code requires raising a ServiceError
9+
#
10+
# @api private
911
def on_complete(env)
1012
status_code = env[:status].to_i
1113
service_error = Github::Error::ServiceError
12-
error_class = service_error.errors[status_code]
13-
error_class = service_error if !error_class and (400...600) === status_code
14+
error_class = service_error.error_mapping[status_code]
15+
if !error_class and (400...600) === status_code
16+
error_class = service_error
17+
end
1418
raise error_class.new(env) if error_class
1519
end
16-
1720
end # Response::RaiseError
1821
end # Github

spec/unit/error/service_error/errors_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require 'spec_helper'
44

5-
RSpec.describe Github::Error::ServiceError, '::errors' do
5+
RSpec.describe Github::Error::ServiceError, '::error_mapping' do
66
it "matches error codes to error types" do
7-
expect(described_class.errors).to include({
7+
expect(described_class.error_mapping).to include({
88
400 => Github::Error::BadRequest,
99
401 => Github::Error::Unauthorized,
1010
403 => Github::Error::Forbidden,

spec/unit/error/service_error_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ def test_request(body='')
3838
Github.repos.branches user, repo
3939
}.to raise_error(Github::Error::NotFound, /key is already in use/)
4040
end
41-
42-
4341
end # Github::Error::ServiceError

0 commit comments

Comments
 (0)