open-graph-scraper
Advanced tools
Comparing version 6.2.0 to 6.2.1
# Change Log | ||
## 6.2.1 | ||
- Send back more details when there is a server error | ||
## 6.2.0 | ||
@@ -4,0 +8,0 @@ |
@@ -25,3 +25,3 @@ "use strict"; | ||
} | ||
const formattedUrl = (0, utils_1.validateAndFormatURL)(options.url, (options.urlValidatorSettings || utils_1.defaultUrlValidatorSettings)); | ||
const formattedUrl = (0, utils_1.validateAndFormatURL)(options.url || '', (options.urlValidatorSettings || utils_1.defaultUrlValidatorSettings)); | ||
if (!formattedUrl.url) | ||
@@ -34,3 +34,3 @@ throw new Error('Invalid URL'); | ||
// eslint-disable-next-line max-len | ||
if (options.blacklist && options.blacklist.some((blacklistedHostname) => options.url.includes(blacklistedHostname))) { | ||
if (options.blacklist && options.blacklist.some((blacklistedHostname) => options.url?.includes(blacklistedHostname))) { | ||
throw new Error('Host name has been black listed'); | ||
@@ -37,0 +37,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
try { | ||
response = await (0, undici_1.fetch)(options.url, { | ||
response = await (0, undici_1.fetch)(options.url || '', { | ||
signal: AbortSignal.timeout((options.timeout || 10) * 1000), | ||
@@ -26,3 +26,26 @@ headers: { Origin: options.url }, | ||
if (response && response.status && (response.status.toString().substring(0, 1) === '4' || response.status.toString().substring(0, 1) === '5')) { | ||
throw new Error('Server has returned a 400/500 error code'); | ||
switch (response.status) { | ||
case 400: | ||
throw new Error('400 Bad Request'); | ||
case 401: | ||
throw new Error('401 Unauthorized'); | ||
case 403: | ||
throw new Error('403 Forbidden'); | ||
case 404: | ||
throw new Error('404 Not Found'); | ||
case 408: | ||
throw new Error('408 Request Timeout'); | ||
case 410: | ||
throw new Error('410 Gone'); | ||
case 500: | ||
throw new Error('500 Internal Server Error'); | ||
case 502: | ||
throw new Error('502 Bad Gateway'); | ||
case 503: | ||
throw new Error('503 Service Unavailable'); | ||
case 504: | ||
throw new Error('504 Gateway Timeout'); | ||
default: | ||
throw new Error('Server has returned a 400/500 error code'); | ||
} | ||
} | ||
@@ -29,0 +52,0 @@ if (body === undefined || body === '') { |
{ | ||
"name": "open-graph-scraper", | ||
"description": "Node.js scraper module for Open Graph and Twitter Card info", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"license": "MIT", | ||
@@ -54,3 +54,3 @@ "main": "./dist/index.js", | ||
"nyc": "^15.1.0", | ||
"sinon": "^15.1.2", | ||
"sinon": "^15.2.0", | ||
"ts-mocha": "^10.0.0", | ||
@@ -57,0 +57,0 @@ "typescript": "^5.1.3" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88150
2115