2011-07-17 08:05:43 +00:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2011-02-15 06:12:45 +00:00
|
|
|
|
/**
|
2011-11-10 06:23:36 +00:00
|
|
|
|
* @ngdoc object
|
2011-11-12 01:15:22 +00:00
|
|
|
|
* @name angular.module.ng.$xhr.error
|
2011-02-15 06:12:45 +00:00
|
|
|
|
* @function
|
|
|
|
|
|
* @requires $log
|
|
|
|
|
|
*
|
|
|
|
|
|
* @description
|
2011-11-12 01:15:22 +00:00
|
|
|
|
* Error handler for {@link angular.module.ng.$xhr $xhr service}. An application can replaces this
|
2011-02-15 06:12:45 +00:00
|
|
|
|
* service with one specific for the application. The default implementation logs the error to
|
2011-11-12 01:15:22 +00:00
|
|
|
|
* {@link angular.module.ng.$log $log.error}.
|
2011-02-15 06:12:45 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param {Object} request Request object.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The object has the following properties
|
|
|
|
|
|
*
|
|
|
|
|
|
* - `method` – `{string}` – The http request method.
|
|
|
|
|
|
* - `url` – `{string}` – The request destination.
|
|
|
|
|
|
* - `data` – `{(string|Object)=} – An optional request body.
|
2011-08-02 07:59:51 +00:00
|
|
|
|
* - `success` – `{function()}` – The success callback function
|
2011-02-15 06:12:45 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param {Object} response Response object.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The response object has the following properties:
|
|
|
|
|
|
*
|
|
|
|
|
|
* - status – {number} – Http status code.
|
|
|
|
|
|
* - body – {string|Object} – Body of the response.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @example
|
|
|
|
|
|
<doc:example>
|
|
|
|
|
|
<doc:source>
|
|
|
|
|
|
fetch a non-existent file and log an error in the console:
|
|
|
|
|
|
<button ng:click="$service('$xhr')('GET', '/DOESNT_EXIST')">fetch</button>
|
|
|
|
|
|
</doc:source>
|
|
|
|
|
|
</doc:example>
|
|
|
|
|
|
*/
|
2011-11-02 23:32:46 +00:00
|
|
|
|
function $XhrErrorProvider() {
|
|
|
|
|
|
this.$get = ['$log', function($log) {
|
|
|
|
|
|
return function(request, response){
|
|
|
|
|
|
$log.error('ERROR: XHR: ' + request.url, request, response);
|
|
|
|
|
|
};
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|