-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass HTTP status to Oktakit::Error.from_response() [description below]
This fixes #59 by modifying `Oktakit::Error.from_response()` method to accept and process client response and HTTP status. The reason behind these changes: ```ruby response, http_status = client.get_user('[email protected]') ``` This usage method is listed in the repo's README and works in most cases. However, it separates response from HTTP status. `response` is a `Sawyer::Resource` object and doesn't contain any data about the request (HTTP status, URL, method or headers). It only has a Hash with Okta error code, error summary, internal error link, error id and error causes, which causes a `TypeError` if we try to `raise Oktakit::Error.from_response(response) unless http_status == 200` in case the user is not found. With these changes implemented, we will gain the ability to process different response formats without causing errors on the client side.
- Loading branch information
1 parent
1c58db5
commit ff1c609
Showing
3 changed files
with
115 additions
and
22 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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require "spec_helper" | ||
|
||
describe Oktakit::Error do | ||
describe "#from_response(response)" do | ||
context "success" do | ||
subject(:from_response) { described_class.from_response(okta_response, 404) } | ||
|
||
context "with response and status" do | ||
let(:okta_response) do | ||
{ | ||
errorCode: "00000000", | ||
errorSummary: "Not found: Resource not found: [email protected] (User)", | ||
errorLink: "E0000007", | ||
errorId: "00000000", | ||
errorCauses: [], | ||
} | ||
end | ||
|
||
it "returns an instance of the described class" do | ||
expect(from_response.class).to(eq(Oktakit::NotFound)) | ||
end | ||
|
||
it "returns a meaningful error message" do | ||
expected_message = "404 - Not found: Resource not found: [email protected] (User)" | ||
|
||
expect(from_response.message).to(eq(expected_message)) | ||
end | ||
end | ||
|
||
context "with missing response" do | ||
let(:okta_response) { {} } | ||
|
||
it "returns an instance of the described class" do | ||
expect(from_response.class).to(eq(Oktakit::NotFound)) | ||
end | ||
|
||
it "returns a meaningful error message" do | ||
expect(from_response.message).to(eq("404")) | ||
end | ||
end | ||
|
||
context "with a different response format" do | ||
let(:okta_response) do | ||
{ | ||
status: 404, | ||
method: "POST", | ||
url: "http://example.com/api/v1", | ||
response_headers: { | ||
content_type: "json", | ||
}, | ||
body: { | ||
errorCode: "E0000007", | ||
errorSummary: "Not found: Resource not found: [email protected] (User)", | ||
errorLink: "E0000007", | ||
errorId: "oaeLRic8zbhTBiJ81eJnWTQUg", | ||
errorCauses: [], | ||
}, | ||
} | ||
end | ||
|
||
it "returns an instance of the described class" do | ||
expect(from_response.class).to(eq(Oktakit::NotFound)) | ||
end | ||
|
||
it "returns a meaningful error message" do | ||
expected_message = "POST http://example.com/api/v1 : 404" | ||
|
||
expect(from_response.message).to(eq(expected_message)) | ||
end | ||
end | ||
end | ||
|
||
context "with errors" do | ||
context "with missing status" do | ||
subject(:from_response) { described_class.from_response(okta_response, 0) } | ||
|
||
let(:okta_response) do | ||
{ | ||
errorCode: "00000000", | ||
errorSummary: "Not found: Resource not found: [email protected] (User)", | ||
errorLink: "E0000007", | ||
errorId: "00000000", | ||
errorCauses: [], | ||
} | ||
end | ||
|
||
it { is_expected.to(be_nil) } | ||
end | ||
end | ||
end | ||
end |