Closed Zren closed 9 years ago
In this case the body should be a string anyway, or at least not an object. Do you have a way to reproduce the error?
body
is an object if you pass json:true
in the request options. Try console.log()ing the err with an invalid apiKey (returns a 401).
var PushBullet = require('pushbullet');
var pusher = new PushBullet('asdfasdfasdfasdf');
pusher.devices(function(err, response) {
console.log(err, response);
console.log(err.message);
pusher.handleResponse = function handleResponse(error, response, body, callback) {
if (error) {
if (typeof callback === 'function') {
callback(error);
}
return;
}
if (response.statusCode !== 200) {
console.log('===========================');
console.log('response.statusCode !== 200');
console.log('response.statusCode', response.statusCode);
console.log('body', body);
console.log('===========================');
if (typeof callback === 'function') {
callback(body);
}
return;
}
if (typeof callback === 'function') {
callback(null, body);
}
};
pusher.devices(function(err, response) {
console.log(err, response);
});
});
[Error: [object Object]] undefined
[object Object]
===========================
response.statusCode !== 200
response.statusCode 401
body { error:
{ type: 'invalid_request',
message: 'Access token is missing or invalid.',
cat: '(=^・ω・^)y=' } }
===========================
{ error:
{ type: 'invalid_request',
message: 'Access token is missing or invalid.',
cat: '(=^・ω・^)y=' } } undefined
Looks like that's a leftover from when json wasn't used everywhere. I'll get this fixed over the weekend.
Fixed in v1.4.2.
https://github.com/alexwhitman/node-pushbullet-api/blob/master/lib/pushbullet.js#L556
The argument entered into Error is .toString()ed.
err.message
is equal to[object Object]
Which tells you nothing.