Skip to content

Commit

Permalink
Merge pull request #17 from AngelList/error-messages
Browse files Browse the repository at this point in the history
More informative error messages for generic errors
  • Loading branch information
kmontag committed Jan 16, 2016
2 parents 0a8590e + 7869e66 commit c822afa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/protip/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class Error < RuntimeError
def initialize(request, response)
@request = request
@response = response

msg = <<-MSG
Received HTTP #{response.code} from #{request.uri}. Response:
#{response.body}
MSG
super(msg)
end

def inspect
Expand Down
2 changes: 1 addition & 1 deletion protip.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
Gem::Specification.new do |spec|
spec.name = 'protip'
spec.version = '0.16.0'
spec.version = '0.16.1'
spec.summary = 'ActiveModel resources backed by protocol buffers'
spec.licenses = ['MIT']
spec.homepage = 'https://github.com/AngelList/protip'
Expand Down
8 changes: 7 additions & 1 deletion test/unit/protip/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,13 @@ def self.it_converts_query_parameters
# Set up an errors instance variable that we can set actual messages on
@errors = Protip::Messages::Errors.new

exception = Protip::UnprocessableEntityError.new mock, mock
request = mock
request.stubs(:uri).returns('http://some.uri')

response = mock
response.stubs(code: 500, body: @errors.to_proto)

exception = Protip::UnprocessableEntityError.new request, response
exception.stubs(:errors).returns @errors
client.stubs(:request).raises(exception)

Expand Down

0 comments on commit c822afa

Please sign in to comment.