Skip to content

Commit

Permalink
🐛 Fix error when pass non-string url in fetch()
Browse files Browse the repository at this point in the history
This commit fixes the error "TypeError: Cannot read properties of
undefined (reading 'split')" which occurs when applying the JavaScript
String split() to the `url` variable that is not a string object.

To prevent this error from occurring, an if-statement has been added to
check the type of the `url` variable and forces the callback return
immediately for non-string values.

This commit addresses issue #82.
  • Loading branch information
chriskyfung committed Dec 1, 2023
1 parent 588e087 commit 5b141f2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ export function fetch(target) {
// For each media URL
if (urls != null && urls.length > 0) {
urls.forEach((url) => {

// Remove query strings from the URL.
if (typeof url !== 'string') {
console.warn('The \'url\' variable is not a string.')
return;
};

// Remove query strings from the URL.
const pathname = url.split('.com')[1].split('?')[0];
// Check if the URL appears in the recent logs.
Expand Down

0 comments on commit 5b141f2

Please sign in to comment.