Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscountCode REST resource can't handle error responses #1255

Open
ClaytonPassmore opened this issue Dec 13, 2023 · 0 comments
Open

DiscountCode REST resource can't handle error responses #1255

ClaytonPassmore opened this issue Dec 13, 2023 · 0 comments

Comments

@ClaytonPassmore
Copy link
Contributor

Issue summary

If Shopify responds with a 4xx or 5xx status code while creating a discount code via the REST API, then a NoMethodError is raised.

  • shopify_api version: 13.3.1
  • Ruby version: 3.2.2
  • Operating system: Ubuntu 22.04 LTS

Expected behavior

  1. The DiscountCode resource should not set @errors to nil on initialization. It should leave it set from the base class as an instance of Rest::BaseErrors
  2. When a ShopifyAPI::Errors::HttpResponseError is encountered during a save, the error is appended onto @errors.errors and the exception is re-raised

Actual behavior

NoMethodError: undefined method `errors' for nil:NilClass

Steps to reproduce the problem

Add the following test case to test/rest/2023_10/discount_code_test.rb and run it. It will blow up with the no method error I described:

  sig do
    void
  end
  def test_10()
    stub_request(:post, "https://test-shop.myshopify.io/admin/api/2023-10/price_rules/507328175/discount_codes.json")
      .to_return(status: 500, body: JSON.generate({"errors":[{"message":"There was a problem loading this website. Please try again.","extensions":{"code":"SERVICE_UNAVAILABLE"}}],"error_reference":"If you report this error, please include this id: 9e6928cf-99cd-47e0-a257-b335115453dc."}), headers: {})

    response = discount_code = ShopifyAPI::DiscountCode.new
    discount_code.price_rule_id = 507328175
    discount_code.code = "SUMMERSALE10OFF"
    discount_code.save!
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants