Files
n8n/packages/nodes-base/nodes/Perplexity/GenericFunctions.ts
alighasami 3d5eaf9445
Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

42 lines
1.5 KiB
TypeScript

import type {
IExecuteSingleFunctions,
IN8nHttpFullResponse,
INodeExecutionData,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
export async function sendErrorPostReceive(
this: IExecuteSingleFunctions,
data: INodeExecutionData[],
response: IN8nHttpFullResponse,
): Promise<INodeExecutionData[]> {
if (String(response.statusCode).startsWith('4') || String(response.statusCode).startsWith('5')) {
const errorBody = response.body as JsonObject;
const error = (errorBody?.error ?? {}) as JsonObject;
const errorMessage =
typeof error.message === 'string'
? error.message
: (response.statusMessage ?? 'An unexpected issue occurred');
const errorType = typeof error.type === 'string' ? error.type : 'UnknownError';
const itemIndex = typeof error.itemIndex === 'number' ? `[Item ${error.itemIndex}]` : '';
if (errorType === 'invalid_model') {
throw new NodeApiError(this.getNode(), errorBody, {
message: 'Invalid model',
description:
'The model is not valid. Permitted models can be found in the documentation at https://docs.perplexity.ai/guides/model-cards.',
});
}
// Fallback for other errors
throw new NodeApiError(this.getNode(), response as unknown as JsonObject, {
message: `${errorMessage}${itemIndex ? ' ' + itemIndex : ''}.`,
description:
'Any optional system messages must be sent first, followed by alternating user and assistant messages. For more details, refer to the API documentation: https://docs.perplexity.ai/api-reference/chat-completions',
});
}
return data;
}