mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-14 00:09:55 +02:00
support sending capability specific error codes
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
AI_CAPABILITY_DEFS,
|
||||
OPENAI_AUTH_ERROR_BODY,
|
||||
type AiCapability
|
||||
} from "@server/lib/aiCapabilities";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
|
||||
export type ClientErrorResponse = {
|
||||
statusCode?: number;
|
||||
contentType?: string;
|
||||
body: string;
|
||||
};
|
||||
|
||||
export function buildInferenceAuthClientError(
|
||||
capability: AiCapability | null
|
||||
): ClientErrorResponse {
|
||||
const body =
|
||||
capability != null
|
||||
? AI_CAPABILITY_DEFS[capability].authErrorBody
|
||||
: OPENAI_AUTH_ERROR_BODY;
|
||||
|
||||
return {
|
||||
statusCode: HttpCode.UNAUTHORIZED,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify(body)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user