Skip to content

Instantly share code, notes, and snippets.

@nrstott
Created August 16, 2010 16:04
Show Gist options
  • Save nrstott/527190 to your computer and use it in GitHub Desktop.
Save nrstott/527190 to your computer and use it in GitHub Desktop.
return when(this.httpClient.request(opts), function success(resp) {
var body = "";
return when(resp.body.forEach(function(chunk) { body += chunk; }), function() {
var val = JSON.parse(body);
if (resp.status >= 400) {
try {
val = JSON.parse(body);
} catch (err) {
val = { error: 'ParseError', reason: body }
}
finally {
throw val;
}
}
return val;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment