Spaces:
Running
Running
| 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=***"); | |
| } | |