• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apowers313 / aiforge / 20962792399

13 Jan 2026 03:39PM UTC coverage: 84.707%. First build
20962792399

push

github

apowers313
feat: initial commit

787 of 905 branches covered (86.96%)

Branch coverage included in aggregate %.

4248 of 5039 new or added lines in 70 files covered. (84.3%)

4248 of 5039 relevant lines covered (84.3%)

13.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.3
/src/server/api/middleware/error.ts
1
/**
2
 * Error handling middleware for API routes
3
 */
4
import type { Request, Response, NextFunction } from 'express';
5
import { logger } from '../../utils/logger.js';
1✔
6

7
/**
8
 * Custom API error class
9
 */
10
export class ApiError extends Error {
1✔
11
  statusCode: number;
34✔
12
  code: string;
34✔
13

14
  constructor(statusCode: number, message: string, code?: string) {
34✔
15
    super(message);
34✔
16
    this.statusCode = statusCode;
34✔
17
    this.code = code ?? 'UNKNOWN_ERROR';
34!
18
    this.name = 'ApiError';
34✔
19
  }
34✔
20

21
  static badRequest(message: string, code?: string): ApiError {
34✔
22
    return new ApiError(400, message, code ?? 'BAD_REQUEST');
2✔
23
  }
2✔
24

25
  static unauthorized(message: string, code?: string): ApiError {
34✔
26
    return new ApiError(401, message, code ?? 'UNAUTHORIZED');
10✔
27
  }
10✔
28

29
  static notFound(message: string, code?: string): ApiError {
34✔
30
    return new ApiError(404, message, code ?? 'NOT_FOUND');
5✔
31
  }
5✔
32

33
  static conflict(message: string, code?: string): ApiError {
34✔
34
    return new ApiError(409, message, code ?? 'CONFLICT');
1✔
35
  }
1✔
36

37
  static internal(message: string, code?: string): ApiError {
34✔
38
    return new ApiError(500, message, code ?? 'INTERNAL_ERROR');
1✔
39
  }
1✔
40

41
  static tooManyRequests(message: string, code?: string): ApiError {
34✔
42
    return new ApiError(429, message, code ?? 'TOO_MANY_REQUESTS');
12✔
43
  }
12✔
44
}
34✔
45

46
/**
47
 * Error handling middleware
48
 */
49
export function errorHandler(
1✔
50
  err: Error,
34✔
51
  _req: Request,
34✔
52
  res: Response,
34✔
53
  _next: NextFunction,
34✔
54
): void {
34✔
55
  if (err instanceof ApiError) {
34✔
56
    res.status(err.statusCode).json({
34✔
57
      error: err.message,
34✔
58
      message: err.message,
34✔
59
      code: err.code,
34✔
60
    });
34✔
61
    return;
34✔
62
  }
34!
63

64
  // Log unexpected errors
NEW
65
  logger.error({ err }, 'Unexpected error');
×
66

NEW
67
  res.status(500).json({
×
NEW
68
    error: 'Internal server error',
×
NEW
69
    code: 'INTERNAL_ERROR',
×
NEW
70
  });
×
NEW
71
}
×
72

73
/**
74
 * 404 handler for unknown routes
75
 */
76
export function notFoundHandler(_req: Request, res: Response): void {
1✔
NEW
77
  res.status(404).json({
×
NEW
78
    error: 'Not found',
×
NEW
79
    code: 'NOT_FOUND',
×
NEW
80
  });
×
NEW
81
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc