SurfSense/surfsense_web/lib/error.ts

62 lines
1.6 KiB
TypeScript
Raw Normal View History

export const SURFSENSE_ISSUES_URL = "https://github.com/MODSetter/SurfSense/issues";
2025-11-14 00:25:08 +02:00
export class AppError extends Error {
2025-11-15 02:07:20 +02:00
status?: number;
statusText?: string;
code?: string;
requestId?: string;
reportUrl?: string;
constructor(
message: string,
status?: number,
statusText?: string,
code?: string,
requestId?: string,
reportUrl?: string
) {
2025-11-14 00:42:19 +02:00
super(message);
this.name = this.constructor.name;
2025-11-15 02:07:20 +02:00
this.status = status;
this.statusText = statusText;
this.code = code;
this.requestId = requestId;
this.reportUrl = reportUrl ?? SURFSENSE_ISSUES_URL;
2025-11-14 00:42:19 +02:00
}
2025-11-14 00:25:08 +02:00
}
export class NetworkError extends AppError {
2025-11-15 02:07:20 +02:00
constructor(message: string, status?: number, statusText?: string) {
super(message, status, statusText, "NETWORK_ERROR");
}
}
export class AbortedError extends AppError {
constructor(message = "Request was cancelled.") {
super(message, undefined, undefined, "REQUEST_ABORTED");
2025-11-14 00:42:19 +02:00
}
2025-11-14 00:25:08 +02:00
}
export class ValidationError extends AppError {
2025-11-15 02:07:20 +02:00
constructor(message: string, status?: number, statusText?: string) {
super(message, status, statusText, "VALIDATION_ERROR");
2025-11-14 00:42:19 +02:00
}
2025-11-14 00:25:08 +02:00
}
export class AuthenticationError extends AppError {
2025-11-15 02:07:20 +02:00
constructor(message: string, status?: number, statusText?: string) {
super(message, status, statusText, "UNAUTHORIZED");
2025-11-14 00:42:19 +02:00
}
2025-11-14 00:25:08 +02:00
}
export class AuthorizationError extends AppError {
2025-11-15 02:07:20 +02:00
constructor(message: string, status?: number, statusText?: string) {
super(message, status, statusText, "FORBIDDEN");
2025-11-15 02:07:20 +02:00
}
}
export class NotFoundError extends AppError {
constructor(message: string, status?: number, statusText?: string) {
super(message, status, statusText, "NOT_FOUND");
2025-11-14 00:42:19 +02:00
}
2025-11-14 00:25:08 +02:00
}