ordercloud-api / ordercloud-javascript-sdk

The official Javascript SDK for the OrderCloud eCommerce platform
MIT License
16 stars 15 forks source link

Invalid character in error responses' JSON #40

Closed ruidfigueiredo closed 5 years ago

ruidfigueiredo commented 5 years ago

When using the ordercloud-javascript-sdk if there's an error, the response that contains the error message seems to contain a character that causes JSON.parse to fail internally in ordercloud. Here's an example:

SyntaxError: Unexpected token  in JSON at position 0
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (.../node_modules/superagent/lib/node/parsers/json.js:11:35)
    at IncomingMessage.emit (events.js:208:15)
    at endReadableNT (_stream_readable.js:1168:12)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  rawResponse: '{"Errors":[{"ErrorCode":"NotAuthorized","Message":"","Data":null}]}',
  statusCode: 403,
  response: undefined
}

Pasting what's on rawResponse to a text editor reveals the issue:

image

ruidfigueiredo commented 5 years ago

That extra character is a byte order mark character:

image

crhistianramirez commented 5 years ago

@ruidfigueiredo this should now be resolved in version 3.5.7

cguedes commented 5 years ago

@crhistianramirez Can you apply this fix to the Auth API? https://github.com/ordercloud-api/OrderCloud-JavaScript-SDK/blob/837a3952a2c7e5c5cdb0434b5e1a3b5a2ed23812/src/Sdk.js#L84