amplience / dc-management-sdk-js

Amplience Dynamic Content Management SDK
https://amplience.github.io/dc-management-sdk-js/
Other
46 stars 14 forks source link

When deleting resources the Amplience SDK attempts to parse "no body" 204 empty string response as JSON #81

Closed kevin-mitchell closed 3 years ago

kevin-mitchell commented 3 years ago

Description

When I attempt to use this library to delete webhooks, an exception is thrown because the HalClient attempts to parse ANY string response from the server as long as the response is a string. But, JSON.parse will complain if the string happens to be an empty string, as is the case with a DELETE request.

Steps to Reproduce

// this examle uses webhooks, but it could be anything resource that when deleted
//  returns a 204 with an empty body
const iveGotALovelyBunchOfWebhooks = await paginator(this.hub.related.webhooks.list);
iveGotALovelyBunchOfWebhooks[0].related.delete();

Expected Results

No errors are thrown, the undefined or otherwise empty return value is returned from call.

Actual Results

...
...
(node:10779) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /Users/kevinmitchell/.../cms-marketing-ui/node_modules/dc-management-sdk-js/build/main/lib/hal/services/HalClient.js:230:62
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
...
...

Affected browsers/environments

(full disclosure: I'm specifically testing on node v12.18.2 and didn't test on other versions. I suspect a similar result though)

Versions

"dc-management-sdk-js": "^1.10.0"

edit - I had wrongly assumed we were on the latest, looks like we were not and this was already fixed!

"dc-management-sdk-js": "^1.8.0"

kevin-mitchell commented 3 years ago

Ha, this is actually already fixed it looks like - we had version 1.8 which didn't have this fix yet.

Sorry for the noise, closing :)