Skip to content

Commit

Permalink
Add new AuthorizationError
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Pheasey committed Oct 5, 2016
1 parent 93180e0 commit 8b0f0c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/riskalyze_api/errors.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module RiskalyzeAPI
class RequestError < StandardError
class RiskalyzeAPIError < StandardError
attr_reader :request

def initialize(msg, request)
@request = request
super msg
end
end

class RequestError < RiskalyzeAPIError
end

class AuthorizationError < RiskalyzeAPIError
end
end
9 changes: 8 additions & 1 deletion lib/riskalyze_api/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ def headers
end

def handle_response(response)
raise RequestError.new(response.response.msg, response.response) if response.code != 200
if response.code != 200
case response.code
when 401
raise AuthorizationError.new(response.response.msg, response.response)
else
raise RequestError.new(response.response.msg, response.response)
end
end

response.parsed_response
end
Expand Down

0 comments on commit 8b0f0c9

Please sign in to comment.