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