Skip to content

Instantly share code, notes, and snippets.

@arv25
Created August 7, 2014 15:37
Show Gist options
  • Save arv25/4026a6aa44c21f0bad35 to your computer and use it in GitHub Desktop.
Save arv25/4026a6aa44c21f0bad35 to your computer and use it in GitHub Desktop.
Error handling for auth service
module Platform::Errors::Handler
def self.included(base)
base.rescue_from Exception do |error|
handle(self, error)
end
end
private
def handle(auth_service, error)
identifier = auth_service.organization.uuid
message = error.message
case error.response.status
when 400..499
fail BadRequest, BadRequest.new(identifier, error).display
else
raise error
end
end
end
class Platform::Errors::BadRequest < StandardError
def initialize(identifier, error)
@identifier = identifier
@error = error
end
def display
"Unable to interact with platform - ( organization_uuid:#{identifier} error message:#{error.message} )"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment