Files
lobe-chat/src/app/api/errorResponse.ts
T
Arvin Xu d5929f6093 feat: support Google / Zhipu / AWS Bedrock model providers (#1173)
*  feat: support claude

*  feat: support google vision

*  feat: add proxy to provider

*  feat: add google config

*  feat: fix google error handle

*  feat: support bedrock error handle

* ♻️ refactor: refactor the auth with jwt

*  test: fix the openai  runtime test

* ♻️ refactor: refactor the settings config

*  feat: refactor the model select in agent setting

* 🎨 chore: improve model list

*  feat: support custom api Key form

* 🎨 chore: improve code

* ♻️ refactor: refactor the custom models

* 💄 style: improve model icon

*  feat: add google handle

* 🌐 style: add i18n

* 📝 docs: add env document about new providers

* 💄 style: improve plugin tag and model options
2024-02-05 12:59:48 +08:00

61 lines
1.7 KiB
TypeScript

import { consola } from 'consola';
import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '@/libs/agent-runtime';
import { ChatErrorType, ErrorResponse, ErrorType } from '@/types/fetch';
const getStatus = (errorType: ILobeAgentRuntimeErrorType | ErrorType) => {
switch (errorType) {
case ChatErrorType.InvalidAccessCode:
case AgentRuntimeErrorType.NoOpenAIAPIKey:
case AgentRuntimeErrorType.InvalidAzureAPIKey:
case AgentRuntimeErrorType.InvalidBedrockCredentials:
case AgentRuntimeErrorType.InvalidZhipuAPIKey:
case AgentRuntimeErrorType.InvalidGoogleAPIKey: {
return 401;
}
case AgentRuntimeErrorType.LocationNotSupportError: {
return 403;
}
// define the 471~480 as provider error
case AgentRuntimeErrorType.AgentRuntimeError: {
return 470;
}
case AgentRuntimeErrorType.OpenAIBizError: {
return 471;
}
case AgentRuntimeErrorType.AzureBizError: {
return 472;
}
case AgentRuntimeErrorType.ZhipuBizError: {
return 473;
}
case AgentRuntimeErrorType.BedrockBizError: {
return 474;
}
case AgentRuntimeErrorType.GoogleBizError: {
return 475;
}
}
return errorType;
};
export const createErrorResponse = (
errorType: ErrorType | ILobeAgentRuntimeErrorType,
body?: any,
) => {
const statusCode = getStatus(errorType);
const data: ErrorResponse = { body, errorType };
if (typeof statusCode !== 'number' || statusCode < 200 || statusCode > 599) {
consola.error(
`current StatusCode: \`${statusCode}\` .`,
'Please go to `./src/app/api/errorResponse.ts` to defined the statusCode.',
);
}
return new Response(JSON.stringify(data), { status: statusCode });
};