error() convenience methods to promises returned by
$http but they don’t work the same as
Versions used below
Chaining off of then()
fn1 has signaled it is done,
fn2 will run. Nothing new here, this is just promises chaining like you’d expect.
One thing to note is the response object is passed to fulfill handlers and reject handlers. This does not follow the convention of passing an
Error to reject handlers.
success() after then()
This fails because the promise returned by
then() is a plain old
$q promise. It doesn’t have the http-specific
Chaining off of success() and error()
Taking a peek at the code, we see that
error() return the original http promise and not the promise generated by your callback. The callback’s return value is ignored.
Chaining off of
success() is possible but it does not work like chaining off of
fn2 will not wait for
fn1 and they’re essentially run in parallel.
What do success() and error() provide?
error() methods pass properties of the response object to their callback.
You save a little typing and use slightly less generic names but I’m not sure it’s worth the potential confusion.