File size: 1,381 Bytes
da2e594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * Custom error class for validation service failures
 */
export class ValidationServiceError extends Error {
  constructor(
    message: string,
    public readonly nodeType?: string,
    public readonly property?: string,
    public readonly cause?: Error
  ) {
    super(message);
    this.name = 'ValidationServiceError';

    // Maintains proper stack trace for where our error was thrown (only available on V8)
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, ValidationServiceError);
    }
  }

  /**
   * Create error for JSON parsing failure
   */
  static jsonParseError(nodeType: string, cause: Error): ValidationServiceError {
    return new ValidationServiceError(
      `Failed to parse JSON data for node ${nodeType}`,
      nodeType,
      undefined,
      cause
    );
  }

  /**
   * Create error for node not found
   */
  static nodeNotFound(nodeType: string): ValidationServiceError {
    return new ValidationServiceError(
      `Node type ${nodeType} not found in repository`,
      nodeType
    );
  }

  /**
   * Create error for critical data extraction failure
   */
  static dataExtractionError(nodeType: string, dataType: string, cause?: Error): ValidationServiceError {
    return new ValidationServiceError(
      `Failed to extract ${dataType} for node ${nodeType}`,
      nodeType,
      dataType,
      cause
    );
  }
}