2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Adding error handling when missing url (#3791)

* Fixing error message when missing url

* Fixing missing url

* Adding missing url case

* Update Axios.js

* Update requests.spec.js

* Update api.spec.js

* Update api.spec.js

* Update api.spec.js

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Hirotaka Tagawa / wafuwafu13
2021-12-23 17:53:40 +09:00
committed by GitHub
parent 99648153ce
commit 95792908f0
3 changed files with 26 additions and 1 deletions
+7
View File
@@ -36,6 +36,10 @@ Axios.prototype.request = function request(configOrUrl, config) {
config = configOrUrl || {};
}
if (!config.url) {
throw new Error('Provided config url is not valid');
}
config = mergeConfig(this.defaults, config);
// Set config.method
@@ -118,6 +122,9 @@ Axios.prototype.request = function request(configOrUrl, config) {
};
Axios.prototype.getUri = function getUri(config) {
if (!config.url) {
throw new Error('Provided config url is not valid');
}
config = mergeConfig(this.defaults, config);
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
};
+1 -1
View File
@@ -11,7 +11,7 @@ describe('static api', function () {
});
it('should have promise method helpers', function () {
var promise = axios();
var promise = axios('/test');
expect(typeof promise.then).toEqual('function');
expect(typeof promise.catch).toEqual('function');
+18
View File
@@ -7,6 +7,24 @@ describe('requests', function () {
jasmine.Ajax.uninstall();
});
it('should throw error when missing url', function (done) {
expect(() => axios()).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios('')).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios({
url: undefined,
})).toThrowError(/Provided config url is not valid/);
done();
expect(() => axios({
method: 'POST',
})).toThrowError(/Provided config url is not valid/);
done();
});
it('should treat single string arg as url', function (done) {
axios('/foo');