Skip to content

Commit 01d9e1f

Browse files
committed
Add new client side error type for detecting wrong parameter values.
1 parent 80aff1f commit 01d9e1f

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/github_api/error.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def initialize(message)
2929
client_error
3030
invalid_options
3131
required_params
32+
unknown_value
3233
].each do |error|
3334
require "github_api/error/#{error}"
3435
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# encoding: utf-8
2+
3+
module Github #:nodoc
4+
# Raised when invalid options are passed to a request body
5+
module Error
6+
class UnknownValue < ClientError
7+
def initialize(key, value, permitted)
8+
super(
9+
generate_message(
10+
:problem => "Wrong value of '#{value}' for the parameter: #{key} provided for this request.",
11+
:summary => "Github gem checks the request parameters passed to ensure that github api is not hit unnecessairly and fails fast.",
12+
:resolution => "Permitted values are: #{permitted}, make sure these are the ones you are using"
13+
)
14+
)
15+
end
16+
end
17+
end # Error
18+
end # Github
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Error::UnknownValue do
6+
describe '#message' do
7+
let(:error) { described_class.new(:state, 'open', "closed, deleted") }
8+
9+
it 'contains the problem in the message' do
10+
error.message.should include "Wrong value of 'open' for the parameter: state provided for this request"
11+
end
12+
13+
it 'contains the summary in the message' do
14+
error.message.should include "Github gem checks the request parameters passed to ensure that github api is not hit unnecessairly and fails fast."
15+
end
16+
17+
it 'contains the resolution in the message' do
18+
error.message.should include "Permitted values are: closed, deleted, make sure these are the ones you are using"
19+
end
20+
end
21+
end # Github::Error::UnkownValue

0 commit comments

Comments
 (0)