Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15x 15x 15x 1x 1x 1x 1x | /**
* Standard error classes for the application
*
* These provide typed, semantic errors with appropriate HTTP status codes
* for consistent error handling across the application.
*/
/**
* Base application error class
* All custom errors should extend this class
*/
export class AppError extends Error {
constructor(
message: string,
public statusCode: number = 500,
public code: string = "INTERNAL_ERROR"
) {
super(message);
this.name = "AppError";
Object.setPrototypeOf(this, AppError.prototype);
}
}
/**
* Validation error for invalid input data
* HTTP Status: 400 Bad Request
*/
export class ValidationError extends AppError {
constructor(message: string, public field?: string) {
super(message, 400, "VALIDATION_ERROR");
this.name = "ValidationError";
}
}
/**
* Authentication error for missing or invalid credentials
* HTTP Status: 401 Unauthorized
*/
export class AuthenticationError extends AppError {
constructor(message: string = "Authentication required") {
super(message, 401, "AUTHENTICATION_ERROR");
this.name = "AuthenticationError";
}
}
/**
* Authorization error for insufficient permissions
* HTTP Status: 403 Forbidden
*/
export class AuthorizationError extends AppError {
constructor(message: string = "Insufficient permissions") {
super(message, 403, "AUTHORIZATION_ERROR");
this.name = "AuthorizationError";
}
}
/**
* Not found error for missing resources
* HTTP Status: 404 Not Found
*/
export class NotFoundError extends AppError {
constructor(resource: string = "Resource") {
super(`${resource} not found`, 404, "NOT_FOUND");
this.name = "NotFoundError";
}
}
/**
* Conflict error for resource conflicts (e.g., duplicate entries)
* HTTP Status: 409 Conflict
*/
export class ConflictError extends AppError {
constructor(message: string) {
super(message, 409, "CONFLICT");
this.name = "ConflictError";
}
}
/**
* Rate limit error for too many requests
* HTTP Status: 429 Too Many Requests
*/
export class RateLimitError extends AppError {
constructor(
message: string = "Too many requests",
public retryAfter?: number
) {
super(message, 429, "RATE_LIMIT_EXCEEDED");
this.name = "RateLimitError";
}
}
/**
* Bad request error for malformed requests
* HTTP Status: 400 Bad Request
*/
export class BadRequestError extends AppError {
constructor(message: string = "Bad request") {
super(message, 400, "BAD_REQUEST");
this.name = "BadRequestError";
}
}
/**
* Unprocessable entity error for valid but unprocessable requests
* HTTP Status: 422 Unprocessable Entity
*/
export class UnprocessableEntityError extends AppError {
constructor(message: string = "Unprocessable entity") {
super(message, 422, "UNPROCESSABLE_ENTITY");
this.name = "UnprocessableEntityError";
}
}
/**
* Service unavailable error for temporary service issues
* HTTP Status: 503 Service Unavailable
*/
export class ServiceUnavailableError extends AppError {
constructor(message: string = "Service temporarily unavailable") {
super(message, 503, "SERVICE_UNAVAILABLE");
this.name = "ServiceUnavailableError";
}
}
/**
* Database error for database-related issues
* HTTP Status: 500 Internal Server Error
*/
export class DatabaseError extends AppError {
constructor(message: string = "Database operation failed") {
super(message, 500, "DATABASE_ERROR");
this.name = "DatabaseError";
}
}
/**
* Payment error for payment-related issues
* HTTP Status: 402 Payment Required
*/
export class PaymentError extends AppError {
constructor(message: string = "Payment failed") {
super(message, 402, "PAYMENT_ERROR");
this.name = "PaymentError";
}
}
/**
* Type guard to check if an error is an AppError
*/
export function isAppError(error: unknown): error is AppError {
return error instanceof AppError;
}
/**
* Type guard to check if an error is a specific type
*/
export function isErrorType<T extends AppError>(
error: unknown,
ErrorClass: new (...args: never[]) => T
): error is T {
return error instanceof ErrorClass;
}
|