mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix ($http): throw error when string URL is provided
This commit is contained in:
committed by
Chirayu Krishnappa
parent
7a374691b9
commit
e9b9421cdb
10
docs/content/error/$http/badreq.ngdoc
Normal file
10
docs/content/error/$http/badreq.ngdoc
Normal file
@@ -0,0 +1,10 @@
|
||||
@ngdoc error
|
||||
@name $http:badreq
|
||||
@fullName Bad Request Configuration
|
||||
@description
|
||||
|
||||
This error occurs when the request configuration parameter passed to the {@link ng.$http `$http`} service is not an object. `$http` expects a single parameter, the request configuration object, but received a parameter that was not an object. The error message should provide additional context such as the actual value of the parameter that was received. If you passed a string parameter, perhaps you meant to call one of the shorthand methods on `$http` such as `$http.get(…)`, etc.
|
||||
|
||||
To resolve this error, make sure you pass a valid request configuration object to `$http`.
|
||||
|
||||
For more information, see the {@link ng.$http `$http`} service API documentation.
|
||||
@@ -743,6 +743,10 @@ function $HttpProvider() {
|
||||
};
|
||||
var headers = mergeHeaders(requestConfig);
|
||||
|
||||
if (!angular.isObject(requestConfig)) {
|
||||
throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
|
||||
}
|
||||
|
||||
extend(config, requestConfig);
|
||||
config.headers = headers;
|
||||
config.method = uppercase(config.method);
|
||||
|
||||
@@ -285,6 +285,12 @@ describe('$http', function() {
|
||||
$http = $h;
|
||||
}]));
|
||||
|
||||
it('should throw error if the request configuration is not an object', inject(function($httpBackend, $http) {
|
||||
expect(function() {
|
||||
$http('/url');
|
||||
}).toThrowMinErr('$http','badreq', 'Http request configuration must be an object. Received: /url');
|
||||
}));
|
||||
|
||||
it('should send GET requests if no method specified', inject(function($httpBackend, $http) {
|
||||
$httpBackend.expect('GET', '/url').respond('');
|
||||
$http({url: '/url'});
|
||||
|
||||
Reference in New Issue
Block a user