Skip to content

Commit

Permalink
Better error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Dec 9, 2019
1 parent e4d7d2f commit fcbc2f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/async/rest/error.rb
Expand Up @@ -26,7 +26,21 @@ class Error < StandardError
class RequestError < Error
end

class UnsupportedError < Error
end

class ResponseError < Error
def initialize(response)
super(response.read)

@response = response
end

def to_s
"#{@response}: #{super}"
end

attr :response
end
end
end
2 changes: 1 addition & 1 deletion lib/async/rest/representation.rb
Expand Up @@ -116,7 +116,7 @@ def value!
@metadata = response.headers
@value = response.read
else
raise ResponseError, response.read
raise ResponseError, response
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/async/rest/wrapper/generic.rb
Expand Up @@ -36,6 +36,7 @@ def process_response(request, response)
end

def parser_for(response)
# It's not always clear why this error is being thrown.
return Unsupported
end

Expand All @@ -50,7 +51,7 @@ def wrap_response(response)

class Unsupported < HTTP::Body::Wrapper
def join
raise ResponseError, super
raise UnsupportedError, super
end
end
end
Expand Down

0 comments on commit fcbc2f1

Please sign in to comment.