fix(http): throw if url is not string or Request
Closes #4245 Closes #4257
This commit is contained in:
parent
dd9b3b4ed0
commit
3525d8a394
|
@ -120,6 +120,8 @@ export class Http {
|
|||
new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url)));
|
||||
} else if (url instanceof Request) {
|
||||
responseObservable = httpRequest(this._backend, url);
|
||||
} else {
|
||||
throw makeTypeError('First argument must be a url string or Request instance.');
|
||||
}
|
||||
return responseObservable;
|
||||
}
|
||||
|
@ -201,6 +203,8 @@ export class Jsonp extends Http {
|
|||
makeTypeError('JSONP requests must use GET request method.');
|
||||
}
|
||||
responseObservable = httpRequest(this._backend, url);
|
||||
} else {
|
||||
throw makeTypeError('First argument must be a url string or Request instance.');
|
||||
}
|
||||
return responseObservable;
|
||||
}
|
||||
|
|
|
@ -103,6 +103,7 @@ export function main() {
|
|||
var injector: Injector;
|
||||
var backend: MockBackend;
|
||||
var baseResponse;
|
||||
var jsonp: Jsonp;
|
||||
beforeEach(() => {
|
||||
injector = Injector.resolveAndCreate([
|
||||
BaseRequestOptions,
|
||||
|
@ -111,9 +112,15 @@ export function main() {
|
|||
function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Http(backend, defaultOptions);
|
||||
},
|
||||
[MockBackend, BaseRequestOptions]),
|
||||
bind(Jsonp).toFactory(
|
||||
function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Jsonp(backend, defaultOptions);
|
||||
},
|
||||
[MockBackend, BaseRequestOptions])
|
||||
]);
|
||||
http = injector.get(Http);
|
||||
jsonp = injector.get(Jsonp);
|
||||
backend = injector.get(MockBackend);
|
||||
baseResponse = new Response(new ResponseOptions({body: 'base response'}));
|
||||
});
|
||||
|
@ -160,6 +167,13 @@ export function main() {
|
|||
// async.done();
|
||||
// });
|
||||
// }));
|
||||
|
||||
|
||||
it('should throw if url is not a string or Request', () => {
|
||||
var req = <Request>{};
|
||||
expect(() => http.request(req))
|
||||
.toThrowError('First argument must be a url string or Request instance.');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -306,5 +320,15 @@ export function main() {
|
|||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Jsonp', () => {
|
||||
describe('.request()', () => {
|
||||
it('should throw if url is not a string or Request', () => {
|
||||
var req = <Request>{};
|
||||
expect(() => jsonp.request(req))
|
||||
.toThrowError('First argument must be a url string or Request instance.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue