-
Notifications
You must be signed in to change notification settings - Fork 474
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
Bug in error handling in Shopify::Rest::Base#save #1202
Comments
Please find the test case and test results below test_case.rb, run with: ruby test_case.rb# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "minitest"
gem "shopify_api", "~> 13.1.0"
gem "webmock", "3.14"
end
require "minitest/autorun"
require "webmock/minitest"
require "shopify_api"
class DiscountCode202204Test < Minitest::Test
def setup
ShopifyAPI::Context.setup(
api_key: "API_KEY",
api_secret_key: "API_SECRET_KEY",
api_version: "2023-07",
host: "https://app-address.com",
scope: ["scope1", "scope2"],
is_private: false,
is_embedded: false,
logger: ::Logger.new(T.let(StringIO.new, StringIO)), # comment line to see logging on stdout
user_agent_prefix: nil,
old_api_secret_key: nil,
log_level: :off,
)
test_session = ShopifyAPI::Auth::Session.new(id: "id", shop: "test-shop.myshopify.io", access_token: "this_is_a_test_token")
ShopifyAPI::Context.activate_session(test_session)
end
def teardown
ShopifyAPI::Context.deactivate_session
end
def test_exception_handling
stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/price_rules/507328175/discount_codes/507328175.json")
.with(
headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"},
body: { "discount_code" => hash_including({"code" => "WINTERSALE20OFF"}) }
)
.to_return(status: 404, body: { errors: "Not Found" }.to_json, headers: {})
discount_code = ShopifyAPI::DiscountCode.new
discount_code.price_rule_id = 507328175
discount_code.id = 507328175
discount_code.code = "WINTERSALE20OFF"
discount_code.save
end
end Test output
|
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue summary
Since v13.0.0 ShopifyAPI::DiscountCode#errors signature has been changed to
Hash
, and #errors is initialized asHash
nil
forDiscountCode
resources.This causes exception in error handling in ShopifyAPI::Rest::Base#save if
ShopifyAPI::Errors::HttpResponseError
is raised during save operation forDiscountCode
resource. Exception is raised becauseHash
nil
does not implement#errors
shopify_api
version: 13.1.0Expected behavior
Rescuing from
ShopifyAPI::Errors::HttpResponseError
does not raise exceptionActual behavior
#<NoMethodError: undefined method `errors' for {}:Hash> is raised#<NoMethodError: undefined method `errors' for nil:NilClass> is raised
Edit: corrected details
The text was updated successfully, but these errors were encountered: