Skip to content

Commit

Permalink
wip: Addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
burivuhster committed Sep 17, 2024
1 parent 7e5119c commit 780cb8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
isChatInstance,
} from '../../../utils/helpers';
import { getTracingConfig } from '../../../utils/tracing';
import { getCustomErrorMessage } from '../../vendors/OpenAi/helpers/error-handling';
import {
getCustomErrorMessage as getCustomOpenAiErrorMessage,
isOpenAiError,
} from '../../vendors/OpenAi/helpers/error-handling';

interface MessagesTemplate {
type: string;
Expand Down Expand Up @@ -586,12 +589,12 @@ export class ChainLlm implements INodeType {
});
});
} catch (error) {
if (error instanceof NodeApiError) {
// If the error is an OpenAI's rate limit error, we want to handle it differently
// because OpenAI has multiple different rate limit errors
// If the error is an OpenAI's rate limit error, we want to handle it differently
// because OpenAI has multiple different rate limit errors
if (error instanceof NodeApiError && isOpenAiError(error.cause)) {
const openAiErrorCode: string | undefined = (error.cause as any).error?.code;
if (openAiErrorCode) {
const customMessage = getCustomErrorMessage(openAiErrorCode);
const customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);
if (customMessage) {
error.message = customMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OpenAIError } from 'openai/error';

const errorMap: Record<string, string> = {
insufficient_quota: 'OpenAI: Insufficient quota',
rate_limit_exceeded: 'OpenAI: Rate limit reached',
Expand All @@ -6,3 +8,7 @@ const errorMap: Record<string, string> = {
export function getCustomErrorMessage(errorCode: string): string | undefined {
return errorMap[errorCode];
}

export function isOpenAiError(error: any): error is OpenAIError {
return error instanceof OpenAIError;
}

0 comments on commit 780cb8d

Please sign in to comment.