Skip to content

Commit

Permalink
Add new fields to error response
Browse files Browse the repository at this point in the history
  • Loading branch information
carloslopdev authored Jun 5, 2024
1 parent becdf18 commit a1103fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/devengo/errors/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
module Devengo
module Errors
class Client < Http
attr_reader :code, :type
attr_reader :code, :type, :title, :detail

def initialize(api_response:, client_error:)
super message: client_error[:message], api_response: api_response

@code = client_error[:code]
@type = client_error[:type]
@title = client_error[:title]
@detail = client_error[:detail]
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/devengo/errors/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
let(:api_response) { double }
let(:body) do
{
error: { message: "Resource not found", code: "account_not_found", type: "not_found_error" },
error: {
message: "Resource not found",
code: "account_not_found",
type: "not_found_error",
title: "Resource not found",
detail: "A resource was not found: Account",
},
exception: "Sample message",
}
end
Expand Down Expand Up @@ -38,6 +44,8 @@
expect(exception_raised.message).to eq "Resource not found"
expect(exception_raised.code).to eq "account_not_found"
expect(exception_raised.type).to eq "not_found_error"
expect(exception_raised.title).to eq "Resource not found"
expect(exception_raised.detail).to eq "A resource was not found: Account"
end
end
end
Expand All @@ -53,6 +61,8 @@
expect(exception_raised.message).to eq body
expect(exception_raised.code).to be_nil
expect(exception_raised.type).to be_nil
expect(exception_raised.title).to be_nil
expect(exception_raised.detail).to be_nil
end
end
end
Expand Down

0 comments on commit a1103fb

Please sign in to comment.