Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'change_exception_message'

  • Loading branch information...
commit 7a67f4b47791cb77de33e491df87cef06012c79f 2 parents bcb624f + b7ab2e9
@pengwynn pengwynn authored
View
5 lib/faraday/response/raise_octokit_error.rb
@@ -38,7 +38,10 @@ def error_message(response)
else
''
end
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
+ errors = unless message.empty?
+ body[:errors] ? ": #{body[:errors].map{|e|e[:message]}.join(', ')}" : ''
+ end
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}#{errors}"
end
end
end
View
11 spec/fixtures/v3/validation_failed.json
@@ -0,0 +1,11 @@
+{
+ "errors": [
+ {
+ "field": "name",
+ "message": "name is too short (minimum is 1 characters)",
+ "code": "custom",
+ "resource": "Repository"
+ }
+ ],
+ "message": "Validation Failed"
+}
View
12 spec/octokit/client_spec.rb
@@ -152,5 +152,17 @@
end
end
+ describe "error handling" do
+
+ it "displays validation errors" do
+ stub_patch("https://foo:bar@api.github.com/repos/pengwynn/api-sandbox").
+ to_return(:body => fixture("v3/validation_failed.json"))
+
+ response = Octokit::Client.new(:login => 'foo', :password => 'bar').update_repository('pengwynn/api-sandbox')
+ expect(response.errors.first.message).to eq('name is too short (minimum is 1 characters)')
+ end
+
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.