omise-ruby icon indicating copy to clipboard operation
omise-ruby copied to clipboard

Could you use JSON.parse instead of JSON.load?

Open midnight-wonderer opened this issue 1 year ago • 3 comments

Expected behavior

JSON.parse usage (bad template; there is no place to provide a proper explanation. will comment later)

Actual behavior

JSON.load usage (bad template; there is no place to provide a proper explanation. will comment later)

Steps to reproduce the issue

Simply using the library

Logs

No response

Screenshots

No response

Name and version information

SDK: omise (0.11.0) Package Manager: bundler Operating System: Linux

midnight-wonderer avatar Aug 21 '24 13:08 midnight-wonderer

You see the JSON usage here https://github.com/omise/omise-ruby/blob/a0efda8b226c92943eb4541446e19aeb1c55194a/lib/omise/util.rb#L20

Typically, JSON.load and JSON.parse are somewhat interchangeable. But they differ under some circumstances. And that circumstance just happened today.

MultiJSON, used in Rails projects, allows configuring different JSON parsers. I use Oj in my projects via Oj.optimize_rails.

The issue is, with such configuration, JSON.load will raise Oj::ParseError while JSON.parse will raise JSON::ParserError. And that parse error will occur when there are faults in Omise's responses. Today, the new backend deployed by Opn is at fault for returning malformed JSON, which made me notice the error.

Could you change JSON.load here to JSON.parse?

midnight-wonderer avatar Aug 21 '24 13:08 midnight-wonderer

@midnight-wonderer Thanks for reaching out. We will look into this and let you know about our findings. We will need more details about the issue. Can you please shed more light on the faults in Omise's responses?

aashishgurung avatar Sep 06 '24 08:09 aashishgurung

Disscussed with the support in ticket no. 646321

midnight-wonderer avatar Sep 06 '24 09:09 midnight-wonderer

@midnight-wonderer We are closing this issue as our support team confirmed it has already been resolved. Thank you.

aashishgurung avatar Oct 18 '24 08:10 aashishgurung

@aashishgurung That is that, and this is this.

The internal server error isn't there anymore. But the client software is still broken. I can't rescue the error properly. Should I send a pull request?

midnight-wonderer avatar Oct 18 '24 09:10 midnight-wonderer

@midnight-wonderer Thank you for submitting the PR. We'll review and test the changes, and proceed accordingly.

aashishgurung avatar Oct 18 '24 09:10 aashishgurung