0

Can I handle a non-JSON response in node-rest-client POST method?

This is the error and response i'm getting:

response: [PURGED], error: [SyntaxError: Unexpected token P in JSON at position 0]

Can I somehow avoid getting an error? The function does what is requested. I suppose creating a custom parser is a solution? I don't understand how to achieve it though.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Sugar
  • 125
  • 10

1 Answers1

0

You need to add a "mimetypes" attribute to your client options. For example, something like this should enable you to handle XML as well as JSON responses:

const Client = require('node-rest-client').Client;
var client = new Client({mimetypes:{
    json:["application/json","application/json;charset=utf-8"],
    xml:["application/xml","application/xml;charset=utf-8"]
}});
client.post(...)
Yoni Rabinovitch
  • 5,171
  • 1
  • 23
  • 34
  • Thanks for your response. I've tried that and it's still not working. I tried to add text:["text/plain","text/plain;charset=utf-8"] as well. – Sugar Feb 25 '18 at 12:52