Skip to content

Error in handle_response method when params['response'] is nil #413

@rahul2103

Description

@rahul2103

Steps to Reproduce:

Send request to the Spree::Api::V2::Storefront::IntentsController#handle_response endpoint.
In some cases, the params['response'] parameter is sent as nil in the request payload.

Expected Behavior:

I expect the handle_response method to gracefully handle cases where params['response'] is nil, preventing a NoMethodError. Instead of raising an error, the method should handle this scenario and respond appropriately.

Actual Behavior:

When params['response'] is nil, a NoMethodError is raised in the Spree::Api::V2::Storefront::IntentsController#handle_response method when attempting to access nested attributes. This can be seen in the server logs:

NoMethodError Spree::Api::V2::Storefront::IntentsController#handle_response
undefined method `[]' for nil:NilClass

Code Snippets:

def handle_response
  if params['response']['error']
     invalidate_payment
     render_error_payload(params['response']['error']['message'])
  else
     render_serialized_payload { { message: I18n.t('spree.payment_successfully_authorized') } }
  end
end

Screenshots:

image

Additional Context:

This issue occurs intermittently and is challenging to reproduce consistently. It seems to be related to scenarios where the expected response structure is not received.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions