fix(OpenAI Node): Descriptive errors (#6270)

This commit is contained in:
Michael Kret 2023-05-18 17:20:56 +03:00 committed by GitHub
parent 421949067b
commit 8fdfa3b6b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { sendErrorPostReceive } from './GenericFunctions';
export const chatOperations: INodeProperties[] = [
{
@ -22,6 +23,7 @@ export const chatOperations: INodeProperties[] = [
method: 'POST',
url: '/v1/chat/completions',
},
output: { postReceive: [sendErrorPostReceive] },
},
},
],

View 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;
}

View file

@ -1,4 +1,5 @@
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { sendErrorPostReceive } from './GenericFunctions';
export const imageOperations: INodeProperties[] = [
{
@ -22,6 +23,7 @@ export const imageOperations: INodeProperties[] = [
method: 'POST',
url: '/v1/images/generations',
},
output: { postReceive: [sendErrorPostReceive] },
},
},
],

View file

@ -24,6 +24,7 @@ export class OpenAi implements INodeType {
},
],
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: 'https://api.openai.com',
},
properties: [

View file

@ -1,4 +1,5 @@
import type { INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { sendErrorPostReceive } from './GenericFunctions';
export const textOperations: INodeProperties[] = [
{
@ -22,6 +23,7 @@ export const textOperations: INodeProperties[] = [
method: 'POST',
url: '/v1/completions',
},
output: { postReceive: [sendErrorPostReceive] },
},
},
{
@ -34,6 +36,7 @@ export const textOperations: INodeProperties[] = [
method: 'POST',
url: '/v1/edits',
},
output: { postReceive: [sendErrorPostReceive] },
},
},
{
@ -46,6 +49,7 @@ export const textOperations: INodeProperties[] = [
method: 'POST',
url: '/v1/moderations',
},
output: { postReceive: [sendErrorPostReceive] },
},
},
],