Skip to content

Commit

Permalink
fix(http): throw if url is not string or Request
Browse files Browse the repository at this point in the history
Closes #4245

Closes #4257
  • Loading branch information
Brian Yarger committed Sep 18, 2015
1 parent dd9b3b4 commit 3525d8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/angular2/src/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions modules/angular2/test/http/http_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function main() {
var injector: Injector;
var backend: MockBackend;
var baseResponse;
var jsonp: Jsonp;
beforeEach(() => {
injector = Injector.resolveAndCreate([
BaseRequestOptions,
Expand All @@ -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'}));
});
Expand Down Expand Up @@ -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.');
});
});


Expand Down Expand Up @@ -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.');
});
});
});
});
}

1 comment on commit 3525d8a

@srogers202
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.