janpantel/angular-sails — pull request #43 by TheSharpieOne (2014-12-22 18:54:06+00:00)
Title: Fix(Iss 42): Better Error Handling

Better error handling from newer sails.io. Mimic Angular's $http better.

This will use the newer sails.io JWR (JSON WebSocket Response) which already determines if there is an error. It will resolve/reject based on if there is an error returned in the JWR.

It also maps some of the JWR values to names used by angular `$http` (making it easier to swap/replace `$http` with this).

`.success()` and `.error()` now pass `response.data` (as before), `response.status` (new, [HTTP status](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)), and `response.headers` (new, object) to the function/callback.

example:

```
$sails.get(url).success(function(data, status, headers){
// the first argument, data, is the same as before.
// the second argument, status, is new. i.e. 200
// the third argument, headers, is new. {object}
}).error(function(data, status, headers){
// ....
});
```

**BREAKING CHANGE** To be more in-line with angular's `$http`, `.then()` will pass the whole JWR object with aliases to angular's `$http` names to the callback function. This object looks like:
```
{
status: response HTTP status (alias of statusCode),
statusCode: response HTTP status (alias of status),
body: response body/contents (alias of data),
data: response body/contents (alias of body),
headers: response headers
}
```
Previously, this just passed the body/data. Now, using `.then()` to work the same way, you would need to use
```
$sails.get(url).then(function(myRespArg){
// myRespArg.data is the new way to access the response body/data/contents
var myResp = myRespArg.data
});
```