Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle case of error in header with empty body

  • Loading branch information...
commit 00ca7ac71626bad2e5674e78b732b30f395ee374 1 parent 9f8d56a
@jneander jneander authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 index.js
View
9 index.js
@@ -990,7 +990,14 @@ var apiRequest = function(opts, oauth, sobject, callback) {
}
return request(opts, function(err, res, body) {
- if(!err && res.statusCode == 200 || res.statusCode == 201 || res.statusCode == 202 || res.statusCode == 204) {
+ if(!err && !body) {
+ if(res.headers && res.headers.error) {
+ err = new Error(res.headers.error);
+ } else {
+ err = new Error('Server returned '+res.statusCode+' with an empty response');
+ }
+ callback(err, null);
+ } else if(!err && res.statusCode == 200 || res.statusCode == 201 || res.statusCode == 202 || res.statusCode == 204) {
if(body) body = JSON.parse(body);
// attach the id back to the sobject on insert
if(sobject && body && body.id && !sobject.Id && !sobject.id && !sobject.ID) sobject.Id = body.id;
Please sign in to comment.
Something went wrong with that request. Please try again.