storyblok / storyblok-ruby-client

Storyblok ruby client for easy access of the content delivery api
MIT License
24 stars 11 forks source link

Deleting a datasource_entry results in a JSON::ParseError from attempting to parse the empty string #34

Open cykod opened 1 year ago

cykod commented 1 year ago

This likely happens on other DELETE requests, but I'm currently only running into it attempting to delete datasource_entries via the API.

Successfully calling DELETE on a datasource_entity results in a response code of 204 (No Content) and an empty body which presents as the empty string in rest-client. The API client then attempt to call JSON.parse on the empty string, which results in a thrown exception of JSON::ParserError (859: unexpected token at '') caused by the call at https://github.com/storyblok/storyblok-ruby/blob/1f018c0965f754d2ea47424dd5e5cc153c4a8404/lib/storyblok/client.rb#L174 which calls https://github.com/storyblok/storyblok-ruby/blob/1f018c0965f754d2ea47424dd5e5cc153c4a8404/lib/storyblok/client.rb#L226-L228 Regardless of the return value of the request.

We are on Ruby 2.7.6, but verified the behavior of JSON.parse("") on Ruby 3.2 and it's the same.


Expected Behavior

The API shouldn't attempt to parse the empty body

Current Behavior

The API ignores the lack of a response body and call JSON.parse regardless of the response code or the body.

Steps to Reproduce

  1. Use the Ruby client to delete a valid datasource_entry via the /v1/spaces/[SPACE_ID]/datasource_entries/[entry_id] route
  2. The client will trigger a unexpected token at '' (JSON::ParserError) exception
Djamal-Sadaghiani commented 4 months ago

I am getting the same error when performing a put action for assets on (ruby 3.3.3)