Skip to content

Commit

Permalink
Add validation_errors prop and get_validation_error_messages method t…
Browse files Browse the repository at this point in the history
…o SeamHttpInvalidInputError
  • Loading branch information
andrii-balitskyi committed Jul 30, 2024
1 parent 0e79fcc commit 7df4572
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/seam/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ def initialize(request_id)
end

class SeamHttpInvalidInputError < SeamHttpApiError
attr_reader :validation_errors

def initialize(error, status_code, request_id)
super(error, status_code, request_id)
@code = "invalid_input"
@validation_errors = error["validation_errors"] || {}
end

def get_validation_error_messages(param_name)
@validation_errors.dig(param_name, "_errors") || []
end
end

Expand Down
8 changes: 7 additions & 1 deletion lib/seam/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ def handle_error_response(response, _method, _uri)
data: error["data"]
}

raise Errors::SeamHttpInvalidInputError.new(error_details, status_code, request_id) if error_type == "invalid_input"
if error_type == "invalid_input"
error_details["validation_errors"] = error["validation_errors"]

raise Errors::SeamHttpInvalidInputError.new(
error_details, status_code, request_id
)
end

raise Errors::SeamHttpApiError.new(error_details, status_code, request_id)
end
Expand Down

0 comments on commit 7df4572

Please sign in to comment.