Shopify / Shopify/shopify-api-ruby

DiscountCode REST resource can't handle error responses

Aperta
#1,255 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

good-first-issue
Lingua principale
Ruby
Stelle
1.1k
Fork
484
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da lib/shopify_api/rest/base.rb, dall’inizializzatore della risorsa DiscountCode in lib/shopify_api/rest/resources/2023_10/discount_code.rb e da test/rest/2023_10/discount_code_test.rb. Esegui lo scenario fornito che fallisce con una risposta 500, esamina come save! registra le istanze di HttpResponseError e conferma che DiscountCode conserva Rest::BaseErrors e rilancia l’errore mentre il test passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
ruby
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.