aacerox / node-rest-client

REST API client from node.js
MIT License
377 stars 132 forks source link

Module is crashing when remote web-service is returning no data #134

Closed kumarmugu closed 7 years ago

kumarmugu commented 7 years ago

node-rest-client is crashing if the remote web-service is returning no date (Http code- 200 or 201. But no data).

This is because of the following line of code https://github.com/aacerox/node-rest-client/blob/master/lib/node-rest-client.js#L437

I have overcome this issue by fixing following way

if (this.isJSON(content)){
  if(data){
    var jsonData,
    data = data.toString();
        try {
               jsonData = this.isValidData(data)?JSON.parse(data):data;      
          } catch (err) {
               jsonData = 'Error parsing response. response: [' +
                                data + '], error: [' + err + ']';
          }
    callback(jsonData, res);
 } else{
       callback({}, res);
 }
aacerox commented 7 years ago

Hi I think your problem is not the one you think it is. I've tried with a local server returning no data at all and everything works fine.

Please send more information about the crash to evaluate if if this is or is not an issue.

Thanks.