Skip to content

Commit 30ea43a

Browse files
committed
Change client error to contain all types.
1 parent 160dfe1 commit 30ea43a

7 files changed

Lines changed: 64 additions & 96 deletions

File tree

lib/github_api/error.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ def initialize(message=$!)
2323
def backtrace
2424
@response_message ? @response_message.backtrace : super
2525
end
26-
2726
end # GithubError
2827
end # Error
2928
end # Github
3029

3130
require 'github_api/error/service_error'
3231
require 'github_api/error/client_error'
33-
Dir[File.dirname(__FILE__) + '/error/*.rb'].sort.each do |path|
34-
filename = File.basename(path)
35-
next if ['service_error.rb', 'client_error.rb'].include?(filename)
36-
require "github_api/error/#{filename}"
37-
end

lib/github_api/error/client_error.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,69 @@ def generate_message(attributes)
1919
"\nResolution:\n #{@resolution}"
2020
end
2121
end
22+
23+
# Raised when invalid options are passed to a request body
24+
class InvalidOptions < ClientError
25+
def initialize(invalid, valid)
26+
super(
27+
generate_message(
28+
problem: "Invalid option #{invalid.keys.join(', ')} provided for this request.",
29+
summary: "Github gem checks the request parameters passed to ensure that github api is not hit unnecessairly and to fail fast.",
30+
resolution: "Valid options are: #{valid.join(', ')}, make sure these are the ones you are using"
31+
)
32+
)
33+
end
34+
end
35+
36+
# Raised when invalid options are passed to a request body
37+
class RequiredParams < ClientError
38+
def initialize(provided, required)
39+
super(
40+
generate_message(
41+
problem: "Missing required parameters: #{provided.keys.join(', ')} provided for this request.",
42+
summary: "Github gem checks the request parameters passed to ensure that github api is not hit unnecessairly and to fail fast.",
43+
resolution: "Required parameters are: #{required.join(', ')}, make sure these are the ones you are using"
44+
)
45+
)
46+
end
47+
end
48+
49+
# Raised when invalid options are passed to a request body
50+
class UnknownMedia < ClientError
51+
def initialize(file)
52+
super(
53+
generate_message(
54+
problem: "Unknown content type for: '#{file}' provided for this request.",
55+
summary: "Github gem infers the content type of the resource by calling the mime-types gem type inference.",
56+
resolution: "Please install mime-types gem to infer the resource content type."
57+
)
58+
)
59+
end
60+
end
61+
62+
# Raised when invalid options are passed to a request body
63+
class UnknownValue < ClientError
64+
def initialize(key, value, permitted)
65+
super(
66+
generate_message(
67+
problem: "Wrong value of '#{value}' for the parameter: #{key} provided for this request.",
68+
summary: "Github gem checks the request parameters passed to ensure that github api is not hit unnecessairly and fails fast.",
69+
resolution: "Permitted values are: #{permitted}, make sure these are the ones you are using"
70+
)
71+
)
72+
end
73+
end
74+
75+
class Validations < ClientError
76+
def initialize(errors)
77+
super(
78+
generate_message(
79+
problem: "Attempted to send request with nil arguments for #{errors.keys.join(', ')}.",
80+
summary: 'Each request expects certain number of required arguments.',
81+
resolution: 'Double check that the provided arguments are set to some value that is neither nil nor empty string.'
82+
)
83+
)
84+
end
85+
end
2286
end # Error
2387
end # Github

lib/github_api/error/invalid_options.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/github_api/error/required_params.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/github_api/error/unknown_media.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/github_api/error/unknown_value.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/github_api/error/validations.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)