Created
August 7, 2014 15:37
-
-
Save arv25/4026a6aa44c21f0bad35 to your computer and use it in GitHub Desktop.
Error handling for auth service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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