First unchecked draft for tags
This commit is contained in:
parent
f936e84168
commit
70b132dc6f
51 changed files with 494 additions and 69 deletions
54
src/api/errors/httpErrors.ts
Normal file
54
src/api/errors/httpErrors.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import {HttpStatusCode} from "../apiHelpers/HttpStatusCodes.js";
|
||||
|
||||
/**
|
||||
* Base class for all HTTP-related errors.
|
||||
* Extends the built-in Error with a status code and message
|
||||
* so that they can be handled in a consistent way.
|
||||
*/
|
||||
export class HttpError extends Error {
|
||||
public statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
|
||||
// Restore prototype chain (important when targeting ES5/ES2015+)
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export class ValidationError extends HttpError {
|
||||
constructor(message: string) {
|
||||
super(message, HttpStatusCode.BAD_REQUEST); // Bad Request
|
||||
}
|
||||
}
|
||||
|
||||
export class UnauthorizedError extends HttpError {
|
||||
constructor(message: string = "Unauthorized") {
|
||||
super(message, HttpStatusCode.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
export class ForbiddenError extends HttpError {
|
||||
constructor(message: string = "Forbidden") {
|
||||
super(message, HttpStatusCode.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
export class NotFoundError extends HttpError {
|
||||
constructor(message: string = "Resource not found") {
|
||||
super(message, HttpStatusCode.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
export class ConflictError extends HttpError {
|
||||
constructor(message: string = "Conflict") {
|
||||
super(message, 409);
|
||||
}
|
||||
}
|
||||
|
||||
export class InternalServerError extends HttpError {
|
||||
constructor(message: string = "Internal Server Error") {
|
||||
super(message, 500);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue