mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-03 23:44:07 +00:00
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers. - Create configuration tests to validate loading of defaults and environment overrides. - Add tests for FEDL service to verify data handling and snapshot functionality. - Introduce GitHub service tests to check API data normalization and caching behavior. - Develop monitor service tests for network checks and uptime calculations. - Implement persistence tests to ensure database migrations are idempotent and data persists across restarts. - Add vault service tests for session management and brute-force protection mechanisms. - Include helper functions for test context creation and JSON response handling.
24 lines
934 B
JavaScript
24 lines
934 B
JavaScript
export class AppError extends Error {
|
|
constructor(status, code, message, details, expose = status < 500) {
|
|
super(message);
|
|
this.name = 'AppError';
|
|
this.status = status;
|
|
this.code = code;
|
|
this.details = details;
|
|
this.expose = expose;
|
|
}
|
|
}
|
|
|
|
export const badRequest = (message = 'Invalid request', details) =>
|
|
new AppError(400, 'bad_request', message, details);
|
|
export const unauthorized = (message = 'Unauthorized') =>
|
|
new AppError(401, 'unauthorized', message);
|
|
export const forbidden = (message = 'Forbidden') =>
|
|
new AppError(403, 'forbidden', message);
|
|
export const notFound = (message = 'Not found') =>
|
|
new AppError(404, 'not_found', message);
|
|
export const tooManyRequests = (message = 'Too many requests', retryAfterMs) =>
|
|
new AppError(429, 'rate_limited', message, { retryAfterMs });
|
|
export const unavailable = (message = 'Service unavailable') =>
|
|
new AppError(503, 'unavailable', message);
|