mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(editor): Add documentation link to insufficient quota message (#11777)
This commit is contained in:
55
packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/error-handling.test.ts
vendored
Normal file
55
packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/error-handling.test.ts
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import { RateLimitError } from 'openai';
|
||||
import { OpenAIError } from 'openai/error';
|
||||
|
||||
import { openAiFailedAttemptHandler, getCustomErrorMessage, isOpenAiError } from './error-handling';
|
||||
|
||||
describe('error-handling', () => {
|
||||
describe('getCustomErrorMessage', () => {
|
||||
it('should return the correct custom error message for known error codes', () => {
|
||||
expect(getCustomErrorMessage('insufficient_quota')).toBe(
|
||||
'Insufficient quota detected. <a href="https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/common-issues/#insufficient-quota" target="_blank">Learn more</a> about resolving this issue',
|
||||
);
|
||||
expect(getCustomErrorMessage('rate_limit_exceeded')).toBe('OpenAI: Rate limit reached');
|
||||
});
|
||||
|
||||
it('should return undefined for unknown error codes', () => {
|
||||
expect(getCustomErrorMessage('unknown_error_code')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isOpenAiError', () => {
|
||||
it('should return true if the error is an instance of OpenAIError', () => {
|
||||
const error = new OpenAIError('Test error');
|
||||
expect(isOpenAiError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if the error is not an instance of OpenAIError', () => {
|
||||
const error = new Error('Test error');
|
||||
expect(isOpenAiError(error)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('openAiFailedAttemptHandler', () => {
|
||||
it('should handle RateLimitError and modify the error message', () => {
|
||||
const error = new RateLimitError(
|
||||
429,
|
||||
{ code: 'rate_limit_exceeded' },
|
||||
'Rate limit exceeded',
|
||||
{},
|
||||
);
|
||||
|
||||
try {
|
||||
openAiFailedAttemptHandler(error);
|
||||
} catch (e) {
|
||||
expect(e).toBe(error);
|
||||
expect(e.message).toBe('OpenAI: Rate limit reached');
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw the error if it is not a RateLimitError', () => {
|
||||
const error = new Error('Test error');
|
||||
|
||||
expect(() => openAiFailedAttemptHandler(error)).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import { OpenAIError } from 'openai/error';
|
||||
import { RateLimitError } from 'openai';
|
||||
import { OpenAIError } from 'openai/error';
|
||||
|
||||
const errorMap: Record<string, string> = {
|
||||
insufficient_quota: 'OpenAI: Insufficient quota',
|
||||
insufficient_quota:
|
||||
'Insufficient quota detected. <a href="https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/common-issues/#insufficient-quota" target="_blank">Learn more</a> about resolving this issue',
|
||||
rate_limit_exceeded: 'OpenAI: Rate limit reached',
|
||||
};
|
||||
|
||||
@@ -23,7 +24,10 @@ export const openAiFailedAttemptHandler = (error: any) => {
|
||||
const customErrorMessage = getCustomErrorMessage(errorCode);
|
||||
|
||||
if (customErrorMessage) {
|
||||
error.message = customErrorMessage;
|
||||
if (error.error) {
|
||||
(error.error as { message: string }).message = customErrorMessage;
|
||||
error.message = customErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user