Spaces:
Running
Running
File size: 1,035 Bytes
3798d02 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import type { ToolResponse } from "./not-found.js";
/** ๋ฒ์ ์ฒ API ํธ์ถ ์คํจ ๋ฑ ์ธ๋ถ ์์กด ์๋ฌ */
export class LawApiError extends Error {
constructor(
message: string,
public readonly statusCode?: number,
public readonly cause?: unknown
) {
super(message);
this.name = "LawApiError";
}
}
/** ์
๋ ฅ ๊ฒ์ฆ ์คํจ */
export class ValidationError extends Error {
constructor(message: string) {
super(message);
this.name = "ValidationError";
}
}
/** ๋ชจ๋ ๋๊ตฌ ์๋ต์ ๊ณตํต ์ ์ฉ. API ํค ๋ง์คํน ํฌํจ. */
export function formatToolError(error: unknown, toolName: string): ToolResponse {
const message = error instanceof Error ? error.message : String(error);
return {
content: [{ type: "text", text: `[ERROR] ${toolName}: ${maskApiKey(message)}` }],
isError: true,
};
}
/** ์๋ฌ ๋ฉ์์งยท๋ก๊ทธ์ OC API ํค๊ฐ ๋
ธ์ถ๋์ง ์๋๋ก ๋ง์คํน */
export function maskApiKey(text: string): string {
return text.replace(/OC=[^&\s]+/gi, "OC=***");
}
|