Skip to content

Instantly share code, notes, and snippets.

@rantler
Last active August 6, 2018 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rantler/24c544f9915a63a976ff5346af093cde to your computer and use it in GitHub Desktop.
Save rantler/24c544f9915a63a976ff5346af093cde to your computer and use it in GitHub Desktop.
Raise custom exception on request error
class ApprovalError < StandardError
def initialize(response)
@response = response
@request = response.request
end
def inspect
"uri: #{@request.uri}, response_body: #{@response.body}"
end
end
class ApprovalBadGatewayError < ApprovalError; end
class ApprovalInternalServerError < ApprovalError; end
module Fontana
module Approval
class Workflow
def update
result = self.class.put(
"#{approvals_api_uri}/#{id}",
:headers => approval_request_headers,
:body => to_json
)
handle_approval_error(response) unless result.success?
# ...
def handle_approval_error(response)
case response.code
when '502'
raise ApprovalBadGatewayError.new(response)
when '500'
raise ApprovalInternalServerError.new(reponse)
else
raise ApprovalError.new(reponse)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment