diff --git a/docs/client/api.html b/docs/client/api.html index 4300236b42..68d3d4cfd4 100644 --- a/docs/client/api.html +++ b/docs/client/api.html @@ -2826,12 +2826,13 @@ standard `x-www-form-urlencoded` content type, unless the `content` or `data` option is used to specify a body, in which case the parameters will be appended to the URL instead. -The callback receives two arguments, `error` and `result`. The `error` -argument will contain an Error if the request fails in any way, -including a network error, time-out, or an HTTP status code in the 400 -or 500 range. The result object is always -defined. When run in synchronous mode, the `result` is returned from the -function, and the `error` value is a stored as a property in `result`. +The callback receives two arguments, `error` and `result`. The +`error` argument will contain an Error if the request fails in any +way, including a network error, time-out, or an HTTP status code in +the 400 or 500 range. In case of a 4xx/5xx HTTP status code, the +`response` property on `error` matches the contents the result object +would have had otherwise. When run in synchronous mode, either +`result` is returned from the function, or `error` is thrown. Contents of the result object: @@ -2853,11 +2854,6 @@ Contents of the result object: Object
A dictionary of HTTP headers from the response.
-
error - Error
-
Error object if the request failed. Matches the error callback parameter.
- - Example server method: diff --git a/packages/http/httpcall_server.js b/packages/http/httpcall_server.js index e3f24157ed..e7554b0daa 100644 --- a/packages/http/httpcall_server.js +++ b/packages/http/httpcall_server.js @@ -65,7 +65,10 @@ Meteor.http.call = function(method, url, options, callback) { // Sync mode fut = new Future; callback = function(error, result) { - fut.ret(result); + if (error) + fut.throw(error); + else + fut.ret(result); }; } else { // Async mode @@ -75,13 +78,13 @@ Meteor.http.call = function(method, url, options, callback) { }); } - // wrap callback to always return a result object, and always - // have an 'error' property in result + // wrap callback to add a 'response' property on an error, in case + // we have both (http 4xx/5xx error, which has a response payload) callback = (function(callback) { - return function(error, result) { - result = result || {}; - result.error = error; - callback(error, result); + return function(error, response) { + if (error && response) + error.response = response; + callback(error, response); }; })(callback);