mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
fix(OpenAI Node): Descriptive errors (#6270)
This commit is contained in:
parent
421949067b
commit
8fdfa3b6b8
|
@ -1,4 +1,5 @@
|
||||||
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||||
|
import { sendErrorPostReceive } from './GenericFunctions';
|
||||||
|
|
||||||
export const chatOperations: INodeProperties[] = [
|
export const chatOperations: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,7 @@ export const chatOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/chat/completions',
|
url: '/v1/chat/completions',
|
||||||
},
|
},
|
||||||
|
output: { postReceive: [sendErrorPostReceive] },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
18
packages/nodes-base/nodes/OpenAi/GenericFunctions.ts
Normal file
18
packages/nodes-base/nodes/OpenAi/GenericFunctions.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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')) {
|
||||||
|
throw new NodeApiError(this.getNode(), response as unknown as JsonObject);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||||
|
import { sendErrorPostReceive } from './GenericFunctions';
|
||||||
|
|
||||||
export const imageOperations: INodeProperties[] = [
|
export const imageOperations: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,7 @@ export const imageOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/images/generations',
|
url: '/v1/images/generations',
|
||||||
},
|
},
|
||||||
|
output: { postReceive: [sendErrorPostReceive] },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -24,6 +24,7 @@ export class OpenAi implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
requestDefaults: {
|
requestDefaults: {
|
||||||
|
ignoreHttpStatusErrors: true,
|
||||||
baseURL: 'https://api.openai.com',
|
baseURL: 'https://api.openai.com',
|
||||||
},
|
},
|
||||||
properties: [
|
properties: [
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||||
|
import { sendErrorPostReceive } from './GenericFunctions';
|
||||||
|
|
||||||
export const textOperations: INodeProperties[] = [
|
export const textOperations: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,7 @@ export const textOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/completions',
|
url: '/v1/completions',
|
||||||
},
|
},
|
||||||
|
output: { postReceive: [sendErrorPostReceive] },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -34,6 +36,7 @@ export const textOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/edits',
|
url: '/v1/edits',
|
||||||
},
|
},
|
||||||
|
output: { postReceive: [sendErrorPostReceive] },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -46,6 +49,7 @@ export const textOperations: INodeProperties[] = [
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/v1/moderations',
|
url: '/v1/moderations',
|
||||||
},
|
},
|
||||||
|
output: { postReceive: [sendErrorPostReceive] },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue