From 1163588aa288160282866057efcaef57dbbe417b Mon Sep 17 00:00:00 2001 From: Daniel <82655381+djs113@users.noreply.github.com> Date: Tue, 18 Jan 2022 22:20:33 +0530 Subject: [PATCH] Added errors to be displayed when the query parsing process itself fails. (#3961) * Adding errors when the query parsing process fails * Updated error * Removed unused variables Co-authored-by: Jay --- lib/adapters/http.js | 10 ++++++++++ test/unit/adapters/http.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index c36f0c7..951e400 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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(), diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 42c6358..018c2fc 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -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';