Skip to content

Commit

Permalink
Added errors to be displayed when the query parsing process itself fa…
Browse files Browse the repository at this point in the history
…ils. (axios#3961)

* Adding errors when the query parsing process fails

* Updated error

* Removed unused variables

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
djs113 and jasonsaayman committed Jan 18, 2022
1 parent 50cd07c commit e3e34ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -138,6 +138,16 @@ module.exports = function httpAdapter(config) {
var isHttpsRequest = isHttps.test(protocol);
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;

try {
buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, '');
} catch (err) {
var customErr = new Error(err.message);
customErr.config = config;
customErr.url = config.url;
customErr.exists = true;
reject(customErr);
}

var options = {
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method.toUpperCase(),
Expand Down
15 changes: 15 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -492,6 +492,21 @@ describe('supports http with nodejs', function () {
});
});

it('should display error while parsing params', function (done) {
server = http.createServer(function () {

}).listen(4444, function () {
axios.get('http://localhost:4444/', {
params: {
errorParam: new Date(undefined),
},
}).catch(function (err) {
assert.deepEqual(err.exists, true)
done();
});
});
});

it('should support sockets', function (done) {
// Different sockets for win32 vs darwin/linux
var socketName = './test.sock';
Expand Down

0 comments on commit e3e34ce

Please sign in to comment.