2023-12-13 20:08:24 +03:00
|
|
|
import getConfig from '../config/main';
|
2023-09-21 15:32:08 +03:00
|
|
|
|
2023-08-23 12:46:19 +03:00
|
|
|
export abstract class TxtDotError extends Error {
|
2023-08-21 17:35:25 +03:00
|
|
|
code: number;
|
2023-08-23 12:46:19 +03:00
|
|
|
name: string;
|
2023-08-21 17:35:25 +03:00
|
|
|
description: string;
|
|
|
|
|
2023-12-13 20:08:24 +03:00
|
|
|
constructor(code: number, name: string, description: string) {
|
2023-08-21 17:35:25 +03:00
|
|
|
super(description);
|
|
|
|
this.code = code;
|
2023-08-23 12:46:19 +03:00
|
|
|
this.name = name;
|
2023-08-21 17:35:25 +03:00
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EngineParseError extends TxtDotError {
|
|
|
|
constructor(message: string) {
|
2023-12-13 20:08:24 +03:00
|
|
|
super(422, 'EngineParseError', `Parse error: ${message}`);
|
2023-08-21 17:35:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 21:17:56 +03:00
|
|
|
export class NoHandlerFoundError extends TxtDotError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(404, 'NoHandlerFoundError', `No handler found for: ${message}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 17:35:25 +03:00
|
|
|
export class LocalResourceError extends TxtDotError {
|
|
|
|
constructor() {
|
2023-12-13 20:08:24 +03:00
|
|
|
super(403, 'LocalResourceError', 'Proxying local resources is forbidden.');
|
2023-08-21 17:35:25 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-21 16:03:28 +03:00
|
|
|
|
2023-09-21 12:18:12 +03:00
|
|
|
export class NotHtmlMimetypeError extends TxtDotError {
|
|
|
|
constructor() {
|
|
|
|
super(
|
|
|
|
421,
|
2023-12-13 20:08:24 +03:00
|
|
|
'NotHtmlMimetypeError',
|
|
|
|
'Received non-HTML content, ' +
|
|
|
|
(getConfig().proxy_res
|
|
|
|
? 'use proxy instead of parser.'
|
|
|
|
: 'proxying is disabled by the instance admin.')
|
2023-09-21 12:18:12 +03:00
|
|
|
);
|
2023-08-16 13:20:24 +03:00
|
|
|
}
|
|
|
|
}
|