txtdot/src/errors/main.ts
Artemy Egorov 7c72d985f7
Merge pull request from GHSA-4gj5-xj97-j8fp
* ci: add build check to pull requests

* Build(deps-dev): Bump @types/node from 20.10.6 to 20.11.24 (#91)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.10.6 to 20.11.24.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: image compression (#101)

* feat: image compression

* fix: not compress svg

Maybe we should add a function to disable this fix. Since I noticed that if you compress svg in webp it becomes magically smaller.

* Configuration page (#104)

* feat: image compression

* feat: configuration page

* refactor: json stringify

and change engine buttons to ordered list

* fix: engine distributor matching

* fix: formatting

* build: update txtdot version to 1.7.0

* fix: configuration page title

* doc: features (#102)

* fix: ssrf

GHSA-4gj5-xj97-j8fp

Doesn't fully correct the error! You need to configure the server to block requests.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-07 14:49:54 +03:00

56 lines
1.3 KiB
TypeScript

import getConfig from '../config/main';
export abstract class TxtDotError extends Error {
code: number;
name: string;
description: string;
constructor(code: number, name: string, description: string) {
super(description);
this.code = code;
this.name = name;
this.description = description;
}
}
export class EngineParseError extends TxtDotError {
constructor(message: string) {
super(422, 'EngineParseError', `Parse error: ${message}`);
}
}
export class NoHandlerFoundError extends TxtDotError {
constructor(message: string) {
super(404, 'NoHandlerFoundError', `No handler found for: ${message}`);
}
}
export class LocalResourceError extends TxtDotError {
constructor() {
super(403, 'LocalResourceError', 'Proxying local resources is forbidden.');
}
}
export class UnsupportedMimetypeError extends TxtDotError {
constructor(expected: string, got?: string) {
super(
415,
'UnsupportedMimetypeError',
`Unsupported mimetype, expected ${expected}, got ${got}`
);
}
}
export class NotHtmlMimetypeError extends TxtDotError {
constructor() {
super(
421,
'NotHtmlMimetypeError',
'Received non-HTML content, ' +
(getConfig().proxy.enabled
? 'use proxy instead of parser.'
: 'proxying is disabled by the instance admin.')
);
}
}