Skip to content

Commit 48bd379

Browse files
VikalpPDavertMik
authored andcommitted
refactor: check typeof arguments for mock requests in Polly (#1816)
1 parent bc11149 commit 48bd379

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/helper/Polly.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ class Polly extends Helper {
5252
}
5353
}
5454

55+
_validateConfig(config) {
56+
const { url = '' } = config;
57+
if (typeof url !== 'string') {
58+
throw new Error(`Expected type of url(in Polly-config) is string, Found ${typeof url}.`);
59+
}
60+
return config;
61+
}
62+
5563
async _after() {
5664
await this.stopMocking();
5765
}

lib/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ function joinUrl(baseUrl, url) {
306306
}
307307

308308
module.exports.appendBaseUrl = function (baseUrl = '', oneOrMoreUrls) {
309+
if (typeof baseUrl !== 'string') {
310+
throw new Error(`Invalid value for baseUrl: ${baseUrl}`);
311+
}
312+
if (!(typeof oneOrMoreUrls === 'string' || Array.isArray(oneOrMoreUrls))) {
313+
throw new Error(`Expected type of Urls is 'string' or 'array', Found '${typeof oneOrMoreUrls}'.`);
314+
}
309315
// Remove '/' if it's at the end of baseUrl
310316
const lastChar = baseUrl.substr(-1);
311317
if (lastChar === '/') {

0 commit comments

Comments
 (0)