All files / lib errors.ts

100% Statements 18/18
100% Branches 4/4
100% Functions 8/8
100% Lines 18/18

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        994x 994x     994x 994x           262x         262x           34x 34x           100x 100x           514x 514x           7x 7x           60x 60x           7x 7x      
// Custom error classes for consistent error handling
 
export class AppError extends Error {
	constructor(
		public statusCode: number,
		public code: string,
		message: string,
	) {
		super(message);
		this.name = "AppError";
	}
}
 
export class NotFoundError extends AppError {
	constructor(resource: string, id?: string) {
		super(
			404,
			"NOT_FOUND",
			id ? `${resource} with id '${id}' not found` : `${resource} not found`,
		);
		this.name = "NotFoundError";
	}
}
 
export class UnauthorizedError extends AppError {
	constructor(message = "Unauthorized") {
		super(401, "UNAUTHORIZED", message);
		this.name = "UnauthorizedError";
	}
}
 
export class ForbiddenError extends AppError {
	constructor(message = "Forbidden") {
		super(403, "FORBIDDEN", message);
		this.name = "ForbiddenError";
	}
}
 
export class ValidationError extends AppError {
	constructor(message: string) {
		super(400, "VALIDATION_ERROR", message);
		this.name = "ValidationError";
	}
}
 
export class ConflictError extends AppError {
	constructor(message: string) {
		super(409, "CONFLICT", message);
		this.name = "ConflictError";
	}
}
 
export class BadRequestError extends AppError {
	constructor(message: string) {
		super(400, "BAD_REQUEST", message);
		this.name = "BadRequestError";
	}
}
 
export class ConfigurationError extends AppError {
	constructor(message: string) {
		super(503, "CONFIGURATION_ERROR", message);
		this.name = "ConfigurationError";
	}
}