File size: 1,977 Bytes
05c5ed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Simple custom error classes
 */

export class AppError extends Error {
  public readonly code: string;

  constructor(code: string, message: string) {
    super(message);
    this.name = "AppError";
    this.code = code;
  }
}

// 401 Unauthorized Error
export class UnauthorizedError extends AppError {
  constructor(message = "Authentication required") {
    super("UNAUTHORIZED", message);
    this.name = "UnauthorizedError";
  }
}

// 403 Forbidden Error
export class ForbiddenError extends AppError {
  constructor(message = "Access forbidden") {
    super("FORBIDDEN", message);
    this.name = "ForbiddenError";
  }
}

/**
 * File storage error types
 */
export class FileStorageError extends Error {
  constructor(
    message: string,
    public code: string,
    public cause?: unknown,
  ) {
    super(message);
    this.name = "FileStorageError";
  }
}

export class FileNotFoundError extends FileStorageError {
  constructor(fileId: string, cause?: unknown) {
    super(`File not found: ${fileId}`, "FILE_NOT_FOUND", cause);
    this.name = "FileNotFoundError";
  }
}

export class FileTooLargeError extends FileStorageError {
  constructor(size: number, maxSize: number, cause?: unknown) {
    super(
      `File too large: ${size} bytes (max: ${maxSize} bytes)`,
      "FILE_TOO_LARGE",
      cause,
    );
    this.name = "FileTooLargeError";
  }
}

export class StorageQuotaExceededError extends FileStorageError {
  constructor(cause?: unknown) {
    super("Storage quota exceeded", "QUOTA_EXCEEDED", cause);
    this.name = "StorageQuotaExceededError";
  }
}

export class UnsupportedFileTypeError extends FileStorageError {
  constructor(mimeType: string, cause?: unknown) {
    super(`Unsupported file type: ${mimeType}`, "UNSUPPORTED_TYPE", cause);
    this.name = "UnsupportedFileTypeError";
  }
}

export class NotImplementedError extends Error {
  constructor(message: string) {
    super(message);
    this.name = "NotImplementedError";
  }
}