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

Errors not JSON parsable #1033

Closed
Alagaesia93 opened this issue Oct 6, 2022 · 7 comments · Fixed by #1140
Closed

Errors not JSON parsable #1033

Alagaesia93 opened this issue Oct 6, 2022 · 7 comments · Fixed by #1140
Assignees

Comments

@Alagaesia93
Copy link

Issue summary

Write a short description of the issue here ↓

shopify_order = ShopifyAPI::Order.new(session: current_shop.session)
shopify_order.email = '[email protected]'
shopify_order.save! => ShopifyAPI::Errors::HttpResponseError exception
shopify_order.errors.errors.first => ShopifyAPI::Errors::HttpResponseError

returns

#<ShopifyAPI::Errors::HttpResponseError: {"line_items"=>["must have at least one line item"]}                                                                         
If you report this error, please include this id: <id>.> 

I just need something like {line_items: 'must have at least one line item'} to return to the frontend, for example

This is a VERY hacky way I made it work

errors = []
shopify_order.errors.errors.each do |error|
  error = error.to_s
  JSON.parse(error[0..error.index('}')].gsub('=>', ':')).each { |attribute, messages| errors << { attribute: , messages: } }
end

But it's definitely ugly and not performant

The cause of the issue is this line https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/clients/http_client.rb#L66
You are basically adding a simple string to a JSON-array.
It would be easily fixed by
error_messages << { error_id: "If you report this error, please include this id: #{id}."}

Expected behavior

What do you think should happen?

shopify_order.errors.errors.first should return something JSON-parsable, a hash or something similar

Actual behavior

What actually happens?

shopify_order.errors.errors.first returns
#<ShopifyAPI::Errors::HttpResponseError: {"order"=>"Required parameter missing or invalid"}
If you report this error, please include this id: .>
To parse that, you need a tricky ugly code.

Steps to reproduce the problem

  1. Install shopify_api gem, get a session, run the code above

Logs

If applicable, enable the logs as described in the README, and paste the relevant portion here.

Specifications

  • shopify_api version: 12
  • Shopify API version used (example: 2020-07): 2022-07
@jagthedrummer
Copy link

Would love to see some more attention paid to how developers are supposed to handle errors. Has anyone at Shopify actually tried building an app with this version of the gem? It's really painful.

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Dec 18, 2022
@jagthedrummer
Copy link

Not stale.

This bot that marks things as closed even though they haven't been addressed in literally any way seem fairly unfriendly to app developers.

@github-actions github-actions bot removed the Stale label Dec 19, 2022
@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@jagthedrummer
Copy link

Not stale. This bot sucks.

@github-actions github-actions bot removed the Stale label Feb 18, 2023
@cisenor1
Copy link

cisenor1 commented Apr 4, 2023

Not stale. These HTTP errors need to be better explained.

@nelsonwittwer
Copy link
Contributor

Finally getting to this 😬 😅 Let me know what ya'll think of this proposed fix: #1140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants