Open cykod opened 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.
No Content
rest-client
JSON.parse
JSON::ParserError (859: unexpected token at '')
We are on Ruby 2.7.6, but verified the behavior of JSON.parse("") on Ruby 3.2 and it's the same.
JSON.parse("")
The API shouldn't attempt to parse the empty body
The API ignores the lack of a response body and call JSON.parse regardless of the response code or the body.
datasource_entry
/v1/spaces/[SPACE_ID]/datasource_entries/[entry_id]
unexpected token at '' (JSON::ParserError)
I am getting the same error when performing a put action for assets on (ruby 3.3.3)
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 inrest-client
. The API client then attempt to callJSON.parse
on the empty string, which results in a thrown exception ofJSON::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
datasource_entry
via the/v1/spaces/[SPACE_ID]/datasource_entries/[entry_id]
routeunexpected token at '' (JSON::ParserError)
exception