UNPKG

@n8n/n8n-nodes-langchain

Version:
43 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeErrorFromStatus = makeErrorFromStatus; exports.extractGoogleErrorMessage = extractGoogleErrorMessage; function makeErrorFromStatus(statusCode, context) { const errorMessages = { 403: { message: 'Unauthorized for this project', description: 'Check your Google Cloud project ID, that your credential has access to that project and that billing is enabled', }, 404: { message: context?.modelName ? `No model found called '${context.modelName}'` : 'No model found', }, }; return errorMessages[statusCode]; } function readGoogleErrorMessage(data) { const entry = Array.isArray(data) ? data[0] : data; if (entry && typeof entry === 'object' && 'error' in entry) { const innerError = entry.error; if (innerError && typeof innerError.message === 'string') return innerError.message; } return undefined; } function extractGoogleErrorMessage(error) { const fromData = readGoogleErrorMessage(error.response?.data); if (fromData) return fromData; const match = error.message?.match(/status code \d+: ([\s\S]+)/); if (match) { try { return readGoogleErrorMessage(JSON.parse(match[1])) ?? match[1]; } catch { return match[1]; } } return undefined; } //# sourceMappingURL=error-handling.js.map