-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with error code at regenerate_token method. Move extract_er…
…ror_message_from_response and extract_error_attribute_from_response to an specific class. See #4 Create ApiException that will be raised on Cursor when OneLogin API returns an error
- Loading branch information
Showing
5 changed files
with
88 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module OneLogin | ||
module Api | ||
class ApiException < Exception | ||
def initialize(message, code) | ||
super(message) | ||
@code = code | ||
end | ||
end | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
require 'onelogin/api/util/constants' | ||
require 'onelogin/api/util/url_builder' | ||
require 'onelogin/api/util/parser' | ||
|
||
module OneLogin | ||
module Api | ||
module Util | ||
include OneLogin::Api::Util::Constants | ||
include OneLogin::Api::Util::UrlBuilder | ||
include OneLogin::Api::Util::Parser | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module OneLogin | ||
module Api | ||
module Util | ||
module Parser | ||
def extract_error_message_from_response(response) | ||
message = '' | ||
content = JSON.parse(response.body) | ||
if content && content.has_key?('status') | ||
status = content['status'] | ||
if status.has_key?('message') | ||
if status['message'].instance_of?(Hash) | ||
if status['message'].has_key?('description') | ||
message = status['message']['description'] | ||
end | ||
else | ||
message = status['message'] | ||
end | ||
elsif status.has_key?('type') | ||
message = status['type'] | ||
end | ||
end | ||
message | ||
end | ||
|
||
def extract_error_attribute_from_response(response) | ||
attribute = nil | ||
content = JSON.parse(response.body) | ||
if content && content.has_key?('status') | ||
status = content['status'] | ||
if status.has_key?('message') && status['message'].instance_of?(Hash) | ||
if status['message'].has_key?('attribute') | ||
attribute = status['message']['attribute'] | ||
end | ||
end | ||
end | ||
attribute | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |