n8n-nodes-duckduckgo-search
Version:
A powerful and comprehensive n8n community node that seamlessly integrates DuckDuckGo search capabilities into your workflows. Search the web, find images, discover news, and explore videos - all with privacy-focused, reliable results.
74 lines (73 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeExecute = exports.parseApiError = exports.createLibraryErrorResult = exports.isDuckDuckScrapeRegexError = void 0;
function isDuckDuckScrapeRegexError(error) {
const errorMessage = (error === null || error === void 0 ? void 0 : error.message) || '';
return (errorMessage.includes("Cannot read properties of null") ||
errorMessage.includes("reading '1'") ||
errorMessage.includes("SEARCH_REGEX") ||
errorMessage.includes("TypeError: Cannot read properties of null"));
}
exports.isDuckDuckScrapeRegexError = isDuckDuckScrapeRegexError;
function createLibraryErrorResult(operation, query, originalError) {
const isRegexError = isDuckDuckScrapeRegexError(originalError);
if (isRegexError) {
return {
success: false,
error: `DuckDuckGo search is temporarily unavailable due to changes in their website structure. The underlying library (duck-duck-scrape) needs to be updated to handle the new format. This is a known issue affecting many users.`,
results: [],
count: 0,
noResults: true,
libraryIssue: true,
recommendedAction: `Try again later, or consider using alternative search engines. You can also report this issue to the n8n-nodes-duckduckgo maintainers.`
};
}
return {
success: false,
error: `Search failed: ${(originalError === null || originalError === void 0 ? void 0 : originalError.message) || 'Unknown error occurred'}`,
results: [],
count: 0,
noResults: true,
libraryIssue: false,
recommendedAction: `Check your query and try again. If the problem persists, there may be a temporary issue with the search service.`
};
}
exports.createLibraryErrorResult = createLibraryErrorResult;
function parseApiError(error, context) {
const errorMessage = (error === null || error === void 0 ? void 0 : error.message) || '';
if (error.name === 'FetchError' || errorMessage.includes('API request failed')) {
return 'API request failed';
}
if (error.name === 'TimeoutError' || errorMessage.includes('Network request timed out')) {
return 'Network request timed out';
}
if (error.name === 'RateLimitError' || error.httpCode === 429 || errorMessage.includes('Rate limit exceeded')) {
return 'Rate limit exceeded';
}
if (isDuckDuckScrapeRegexError(error)) {
return 'DuckDuckGo search is temporarily unavailable due to changes in their website structure. The underlying library (duck-duck-scrape) needs to be updated to handle the new format. This is a known issue affecting many users.';
}
return `Error during ${context}: ${errorMessage}`;
}
exports.parseApiError = parseApiError;
async function safeExecute(operation, query, searchFunction, debugMode = false) {
try {
const result = await searchFunction();
if (!result || typeof result !== 'object') {
return createLibraryErrorResult(operation, query, new Error('Invalid search result structure'));
}
return result;
}
catch (error) {
if (debugMode) {
console.error(`[${operation}] Error:`, {
query,
error: error === null || error === void 0 ? void 0 : error.message,
stack: error === null || error === void 0 ? void 0 : error.stack,
isRegexError: isDuckDuckScrapeRegexError(error)
});
}
return createLibraryErrorResult(operation, query, error);
}
}
exports.safeExecute = safeExecute;