@tsed/exceptions 8.11.1 → 8.11.2-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/clientErrors/BadMapping.js +0 -1
- package/lib/esm/clientErrors/BadRequest.js +0 -1
- package/lib/esm/clientErrors/Conflict.js +0 -1
- package/lib/esm/clientErrors/ExpectationFailed.js +0 -1
- package/lib/esm/clientErrors/Forbidden.js +0 -1
- package/lib/esm/clientErrors/Gone.js +0 -1
- package/lib/esm/clientErrors/ImATeapot.js +0 -1
- package/lib/esm/clientErrors/LengthRequired.js +0 -1
- package/lib/esm/clientErrors/MethodNotAllowed.js +0 -1
- package/lib/esm/clientErrors/MisdirectedRequest.js +0 -1
- package/lib/esm/clientErrors/NotAcceptable.js +0 -1
- package/lib/esm/clientErrors/NotFound.js +0 -1
- package/lib/esm/clientErrors/PaymentRequired.js +0 -1
- package/lib/esm/clientErrors/PreconditionFailed.js +0 -1
- package/lib/esm/clientErrors/PreconditionRequired.js +0 -1
- package/lib/esm/clientErrors/ProxyAuthentificationRequired.js +0 -1
- package/lib/esm/clientErrors/RequestEntityTooLarge.js +0 -1
- package/lib/esm/clientErrors/RequestHeaderFieldsTooLarge.js +0 -1
- package/lib/esm/clientErrors/RequestRangeUnsatisfiable.js +0 -1
- package/lib/esm/clientErrors/RequestTimeout.js +0 -1
- package/lib/esm/clientErrors/RequestURITooLong.js +0 -1
- package/lib/esm/clientErrors/TooManyRequests.js +0 -1
- package/lib/esm/clientErrors/Unauthorized.js +0 -1
- package/lib/esm/clientErrors/UnavailableForLegalReasons.js +0 -1
- package/lib/esm/clientErrors/UnprocessableEntity.js +0 -1
- package/lib/esm/clientErrors/UnsupportedMediaType.js +0 -1
- package/lib/esm/clientErrors/UpgradeRequired.js +0 -1
- package/lib/esm/core/ClientException.js +0 -1
- package/lib/esm/core/Exception.js +0 -1
- package/lib/esm/core/RedirectException.js +0 -1
- package/lib/esm/core/ServerException.js +0 -1
- package/lib/esm/core/StatusFamily.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/redirections/MovedPermanently.js +0 -1
- package/lib/esm/redirections/MovedTemporarily.js +0 -1
- package/lib/esm/redirections/MultipleChoices.js +0 -1
- package/lib/esm/redirections/NotModified.js +0 -1
- package/lib/esm/redirections/PermanentRedirect.js +0 -1
- package/lib/esm/redirections/SeeOther.js +0 -1
- package/lib/esm/redirections/TemporaryRedirect.js +0 -1
- package/lib/esm/redirections/UseProxy.js +0 -1
- package/lib/esm/serverErrors/BadGateway.js +0 -1
- package/lib/esm/serverErrors/BandwidthLimitExceeded.js +0 -1
- package/lib/esm/serverErrors/GatewayTimeout.js +0 -1
- package/lib/esm/serverErrors/InternalServerError.js +0 -1
- package/lib/esm/serverErrors/NetworkAuthenticationRequired.js +0 -1
- package/lib/esm/serverErrors/NotExtended.js +0 -1
- package/lib/esm/serverErrors/NotImplemented.js +0 -1
- package/lib/esm/serverErrors/ProxyError.js +0 -1
- package/lib/esm/serverErrors/ServiceUnavailable.js +0 -1
- package/lib/esm/serverErrors/VariantAlsoNegotiates.js +0 -1
- package/package.json +7 -4
- package/lib/esm/clientErrors/BadMapping.js.map +0 -1
- package/lib/esm/clientErrors/BadRequest.js.map +0 -1
- package/lib/esm/clientErrors/Conflict.js.map +0 -1
- package/lib/esm/clientErrors/ExpectationFailed.js.map +0 -1
- package/lib/esm/clientErrors/Forbidden.js.map +0 -1
- package/lib/esm/clientErrors/Gone.js.map +0 -1
- package/lib/esm/clientErrors/ImATeapot.js.map +0 -1
- package/lib/esm/clientErrors/LengthRequired.js.map +0 -1
- package/lib/esm/clientErrors/MethodNotAllowed.js.map +0 -1
- package/lib/esm/clientErrors/MisdirectedRequest.js.map +0 -1
- package/lib/esm/clientErrors/NotAcceptable.js.map +0 -1
- package/lib/esm/clientErrors/NotFound.js.map +0 -1
- package/lib/esm/clientErrors/PaymentRequired.js.map +0 -1
- package/lib/esm/clientErrors/PreconditionFailed.js.map +0 -1
- package/lib/esm/clientErrors/PreconditionRequired.js.map +0 -1
- package/lib/esm/clientErrors/ProxyAuthentificationRequired.js.map +0 -1
- package/lib/esm/clientErrors/RequestEntityTooLarge.js.map +0 -1
- package/lib/esm/clientErrors/RequestHeaderFieldsTooLarge.js.map +0 -1
- package/lib/esm/clientErrors/RequestRangeUnsatisfiable.js.map +0 -1
- package/lib/esm/clientErrors/RequestTimeout.js.map +0 -1
- package/lib/esm/clientErrors/RequestURITooLong.js.map +0 -1
- package/lib/esm/clientErrors/TooManyRequests.js.map +0 -1
- package/lib/esm/clientErrors/Unauthorized.js.map +0 -1
- package/lib/esm/clientErrors/UnavailableForLegalReasons.js.map +0 -1
- package/lib/esm/clientErrors/UnprocessableEntity.js.map +0 -1
- package/lib/esm/clientErrors/UnsupportedMediaType.js.map +0 -1
- package/lib/esm/clientErrors/UpgradeRequired.js.map +0 -1
- package/lib/esm/core/ClientException.js.map +0 -1
- package/lib/esm/core/Exception.js.map +0 -1
- package/lib/esm/core/RedirectException.js.map +0 -1
- package/lib/esm/core/ServerException.js.map +0 -1
- package/lib/esm/core/StatusFamily.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/redirections/MovedPermanently.js.map +0 -1
- package/lib/esm/redirections/MovedTemporarily.js.map +0 -1
- package/lib/esm/redirections/MultipleChoices.js.map +0 -1
- package/lib/esm/redirections/NotModified.js.map +0 -1
- package/lib/esm/redirections/PermanentRedirect.js.map +0 -1
- package/lib/esm/redirections/SeeOther.js.map +0 -1
- package/lib/esm/redirections/TemporaryRedirect.js.map +0 -1
- package/lib/esm/redirections/UseProxy.js.map +0 -1
- package/lib/esm/serverErrors/BadGateway.js.map +0 -1
- package/lib/esm/serverErrors/BandwidthLimitExceeded.js.map +0 -1
- package/lib/esm/serverErrors/GatewayTimeout.js.map +0 -1
- package/lib/esm/serverErrors/InternalServerError.js.map +0 -1
- package/lib/esm/serverErrors/NetworkAuthenticationRequired.js.map +0 -1
- package/lib/esm/serverErrors/NotExtended.js.map +0 -1
- package/lib/esm/serverErrors/NotImplemented.js.map +0 -1
- package/lib/esm/serverErrors/ProxyError.js.map +0 -1
- package/lib/esm/serverErrors/ServiceUnavailable.js.map +0 -1
- package/lib/esm/serverErrors/VariantAlsoNegotiates.js.map +0 -1
- package/src/clientErrors/BadMapping.ts +0 -10
- package/src/clientErrors/BadRequest.ts +0 -9
- package/src/clientErrors/Conflict.ts +0 -9
- package/src/clientErrors/ExpectationFailed.ts +0 -9
- package/src/clientErrors/Forbidden.ts +0 -9
- package/src/clientErrors/Gone.ts +0 -9
- package/src/clientErrors/ImATeapot.ts +0 -10
- package/src/clientErrors/LengthRequired.ts +0 -9
- package/src/clientErrors/MethodNotAllowed.ts +0 -9
- package/src/clientErrors/MisdirectedRequest.ts +0 -9
- package/src/clientErrors/NotAcceptable.ts +0 -9
- package/src/clientErrors/NotFound.ts +0 -9
- package/src/clientErrors/PaymentRequired.ts +0 -9
- package/src/clientErrors/PreconditionFailed.ts +0 -9
- package/src/clientErrors/PreconditionRequired.ts +0 -9
- package/src/clientErrors/ProxyAuthentificationRequired.ts +0 -9
- package/src/clientErrors/RequestEntityTooLarge.ts +0 -9
- package/src/clientErrors/RequestHeaderFieldsTooLarge.ts +0 -9
- package/src/clientErrors/RequestRangeUnsatisfiable.ts +0 -9
- package/src/clientErrors/RequestTimeout.ts +0 -9
- package/src/clientErrors/RequestURITooLong.ts +0 -9
- package/src/clientErrors/TooManyRequests.ts +0 -9
- package/src/clientErrors/Unauthorized.ts +0 -9
- package/src/clientErrors/UnavailableForLegalReasons.ts +0 -9
- package/src/clientErrors/UnprocessableEntity.ts +0 -9
- package/src/clientErrors/UnsupportedMediaType.ts +0 -9
- package/src/clientErrors/UpgradeRequired.ts +0 -9
- package/src/core/ClientException.ts +0 -8
- package/src/core/Exception.spec.ts +0 -92
- package/src/core/Exception.ts +0 -108
- package/src/core/RedirectException.ts +0 -8
- package/src/core/ServerException.ts +0 -8
- package/src/core/StatusFamily.ts +0 -5
- package/src/index.ts +0 -53
- package/src/redirections/MovedPermanently.ts +0 -9
- package/src/redirections/MovedTemporarily.ts +0 -10
- package/src/redirections/MultipleChoices.ts +0 -9
- package/src/redirections/NotModified.ts +0 -9
- package/src/redirections/PermanentRedirect.ts +0 -9
- package/src/redirections/SeeOther.ts +0 -9
- package/src/redirections/TemporaryRedirect.ts +0 -9
- package/src/redirections/UseProxy.ts +0 -9
- package/src/serverErrors/BadGateway.ts +0 -9
- package/src/serverErrors/BandwidthLimitExceeded.ts +0 -9
- package/src/serverErrors/GatewayTimeout.ts +0 -9
- package/src/serverErrors/InternalServerError.ts +0 -9
- package/src/serverErrors/NetworkAuthenticationRequired.ts +0 -9
- package/src/serverErrors/NotExtended.ts +0 -9
- package/src/serverErrors/NotImplemented.ts +0 -9
- package/src/serverErrors/ProxyError.ts +0 -10
- package/src/serverErrors/ServiceUnavailable.ts +0 -9
- package/src/serverErrors/VariantAlsoNegotiates.ts +0 -9
- package/vitest.config.mts +0 -21
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class ExpectationFailed extends ClientException {
|
|
4
|
-
static readonly STATUS = 417;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(ExpectationFailed.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
package/src/clientErrors/Gone.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class ImATeapot extends ClientException {
|
|
4
|
-
static readonly STATUS = 418;
|
|
5
|
-
name: string = "IM_A_TEAPOT";
|
|
6
|
-
|
|
7
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
8
|
-
super(ImATeapot.STATUS, message, origin);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class LengthRequired extends ClientException {
|
|
4
|
-
static readonly STATUS = 411;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(LengthRequired.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class MethodNotAllowed extends ClientException {
|
|
4
|
-
static readonly STATUS = 405;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(MethodNotAllowed.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class MisdirectedRequest extends ClientException {
|
|
4
|
-
static readonly STATUS = 421;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(MisdirectedRequest.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class NotAcceptable extends ClientException {
|
|
4
|
-
static readonly STATUS = 406;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin: Error | string | any = "You must accept content-type " + message) {
|
|
7
|
-
super(NotAcceptable.STATUS, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class PaymentRequired extends ClientException {
|
|
4
|
-
static readonly STATUS = 402;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(PaymentRequired.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class PreconditionFailed extends ClientException {
|
|
4
|
-
static readonly STATUS = 412;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(PreconditionFailed.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class PreconditionRequired extends ClientException {
|
|
4
|
-
static readonly STATUS = 428;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(PreconditionRequired.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class ProxyAuthentificationRequired extends ClientException {
|
|
4
|
-
static readonly STATUS = 407;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(ProxyAuthentificationRequired.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class RequestEntityTooLarge extends ClientException {
|
|
4
|
-
static readonly STATUS = 413;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(RequestEntityTooLarge.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class RequestHeaderFieldsTooLarge extends ClientException {
|
|
4
|
-
static readonly STATUS = 431;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(RequestHeaderFieldsTooLarge.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class RequestRangeUnsatisfiable extends ClientException {
|
|
4
|
-
static readonly STATUS = 416;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(RequestRangeUnsatisfiable.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class RequestTimeout extends ClientException {
|
|
4
|
-
static readonly STATUS = 408;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(RequestTimeout.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class RequestURITooLong extends ClientException {
|
|
4
|
-
static readonly STATUS = 414;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(RequestURITooLong.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class TooManyRequests extends ClientException {
|
|
4
|
-
static readonly STATUS = 429;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(TooManyRequests.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class Unauthorized extends ClientException {
|
|
4
|
-
static readonly STATUS = 401;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(Unauthorized.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class UnavailableForLegalReasons extends ClientException {
|
|
4
|
-
static readonly STATUS = 451;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(UnavailableForLegalReasons.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class UnprocessableEntity extends ClientException {
|
|
4
|
-
static readonly STATUS = 422;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(UnprocessableEntity.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class UnsupportedMediaType extends ClientException {
|
|
4
|
-
static readonly STATUS = 415;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(UnsupportedMediaType.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ClientException} from "../core/ClientException.js";
|
|
2
|
-
|
|
3
|
-
export class UpgradeRequired extends ClientException {
|
|
4
|
-
static readonly STATUS = 426;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(UpgradeRequired.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {Exception} from "./Exception.js";
|
|
2
|
-
import {StatusFamily} from "./StatusFamily.js";
|
|
3
|
-
|
|
4
|
-
export class ClientException extends Exception {
|
|
5
|
-
constructor(status: number, message: string, origin?: Error | string | any) {
|
|
6
|
-
super(Exception.validate(status, StatusFamily["4xx"]), message, origin);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {Exception, HTTPException} from "./Exception.js";
|
|
2
|
-
import {StatusFamily} from "./StatusFamily.js";
|
|
3
|
-
|
|
4
|
-
describe("Exception", () => {
|
|
5
|
-
it("should use origin", () => {
|
|
6
|
-
const exception = new Exception(undefined, "test", new Error("test"));
|
|
7
|
-
|
|
8
|
-
exception.setHeader("key", "value");
|
|
9
|
-
|
|
10
|
-
expect(exception.headers).toEqual({
|
|
11
|
-
key: "value"
|
|
12
|
-
});
|
|
13
|
-
expect(exception.status).toEqual(500);
|
|
14
|
-
expect(exception.toString()).toEqual("INTERNAL_SERVER_ERROR(500): test, innerException: test");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should use origin (inner)", () => {
|
|
18
|
-
const exception = new Exception(203, "test", new Error("test"));
|
|
19
|
-
exception.setHeaders({key: "value"});
|
|
20
|
-
|
|
21
|
-
expect(exception.headers).toEqual({
|
|
22
|
-
key: "value"
|
|
23
|
-
});
|
|
24
|
-
expect(exception.status).toEqual(203);
|
|
25
|
-
expect(exception.toString()).toEqual("NON_AUTHORITATIVE_INFORMATION(203): test, innerException: test");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should use origin as string (inner)", () => {
|
|
29
|
-
const exception = new Exception(203, "test", "test");
|
|
30
|
-
|
|
31
|
-
expect(exception.status).toEqual(203);
|
|
32
|
-
expect(exception.toString()).toEqual("NON_AUTHORITATIVE_INFORMATION(203): test, innerException: test");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should use origin as string", () => {
|
|
36
|
-
const exception = new Exception(203, "test", {});
|
|
37
|
-
|
|
38
|
-
expect(exception.status).toEqual(203);
|
|
39
|
-
expect(exception.toString()).toEqual("NON_AUTHORITATIVE_INFORMATION(203): test");
|
|
40
|
-
expect(exception.body).toEqual({});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should return empty message when message parameters is undefined", () => {
|
|
44
|
-
const exception = new Exception(203, undefined);
|
|
45
|
-
|
|
46
|
-
expect(exception.status).toEqual(203);
|
|
47
|
-
expect(exception.toString()).toEqual("NON_AUTHORITATIVE_INFORMATION(203):");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should allow declaring custom status", () => {
|
|
51
|
-
class GatewayUserNotFoundError extends HTTPException {
|
|
52
|
-
public static readonly STATUS = 524;
|
|
53
|
-
|
|
54
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
55
|
-
super(GatewayUserNotFoundError.STATUS, message, origin);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const error = new GatewayUserNotFoundError("test");
|
|
60
|
-
|
|
61
|
-
expect(error.name).toEqual("GATEWAY_USER_NOT_FOUND_ERROR");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should throw exception if status code is less than 100", () => {
|
|
65
|
-
try {
|
|
66
|
-
Exception.validate(90, StatusFamily["4xx"]);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
expect(e.message).toContain("between 100 and 599");
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should throw exception if status code is more than 599", () => {
|
|
73
|
-
try {
|
|
74
|
-
Exception.validate(600, StatusFamily["4xx"]);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
expect(e.message).toContain("between 100 and 599");
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should throw exception if status code does not belong to family", () => {
|
|
81
|
-
try {
|
|
82
|
-
Exception.validate(519, StatusFamily["4xx"]);
|
|
83
|
-
} catch (e) {
|
|
84
|
-
expect(e.message).toContain("does not belong to the family");
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should validate the status code", () => {
|
|
89
|
-
const code = Exception.validate(419, StatusFamily["4xx"]);
|
|
90
|
-
expect(code).toEqual(419);
|
|
91
|
-
});
|
|
92
|
-
});
|
package/src/core/Exception.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {classOf, nameOf} from "@tsed/core";
|
|
2
|
-
import {constantCase} from "change-case";
|
|
3
|
-
import statuses from "statuses";
|
|
4
|
-
|
|
5
|
-
import {StatusFamily} from "./StatusFamily.js";
|
|
6
|
-
|
|
7
|
-
export class Exception extends Error {
|
|
8
|
-
/**
|
|
9
|
-
* Exception base name
|
|
10
|
-
* @type {string}
|
|
11
|
-
*/
|
|
12
|
-
public name: string = "HTTP_EXCEPTION";
|
|
13
|
-
/**
|
|
14
|
-
* Message of the exception
|
|
15
|
-
*/
|
|
16
|
-
public message: string;
|
|
17
|
-
/**
|
|
18
|
-
* Exception type
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
public type: string = "HTTP_EXCEPTION";
|
|
22
|
-
/**
|
|
23
|
-
* Stack calling
|
|
24
|
-
*/
|
|
25
|
-
public stack: string;
|
|
26
|
-
public origin: Error & any;
|
|
27
|
-
/**
|
|
28
|
-
* HTTP Code Status
|
|
29
|
-
*/
|
|
30
|
-
public status: number;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
public body: any;
|
|
35
|
-
/**
|
|
36
|
-
* Headers must be sent to the response
|
|
37
|
-
*/
|
|
38
|
-
public headers: {[key: string]: any} = {};
|
|
39
|
-
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
|
|
42
|
-
public static validate(status: number, family: StatusFamily): number {
|
|
43
|
-
if (status < 100 || status >= 600) {
|
|
44
|
-
throw new Error("Status must be between 100 and 599");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (status.toString()[0] !== family.charAt(0)) {
|
|
48
|
-
throw new Error(`Status ${status} does not belong to the family ${family}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return status;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
constructor(status: number = 500, message: string = "", origin?: Error | string | any) {
|
|
55
|
-
super(message);
|
|
56
|
-
|
|
57
|
-
this.status = status;
|
|
58
|
-
this.message = message;
|
|
59
|
-
this.name = this.#getStatusConstant();
|
|
60
|
-
|
|
61
|
-
this.setOrigin(origin);
|
|
62
|
-
|
|
63
|
-
Error.captureStackTrace(this);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setHeaders(headers: {[key: string]: any}) {
|
|
67
|
-
this.headers = {
|
|
68
|
-
...this.headers,
|
|
69
|
-
...headers
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setHeader(key: string, value: any) {
|
|
76
|
-
this.headers[key] = value;
|
|
77
|
-
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setOrigin(origin: Error | string | any) {
|
|
82
|
-
if (origin) {
|
|
83
|
-
if (origin instanceof Error) {
|
|
84
|
-
this.origin = origin;
|
|
85
|
-
this.message = `${this.message}, innerException: ${this.origin.message}`.trim();
|
|
86
|
-
} else if (typeof origin === "string") {
|
|
87
|
-
this.origin = new Error(origin);
|
|
88
|
-
this.message = `${this.message}, innerException: ${this.origin.message}`.trim();
|
|
89
|
-
} else {
|
|
90
|
-
this.body = origin;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
toString() {
|
|
96
|
-
return `${this.name}(${this.status}): ${this.message} `.trim();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
#getStatusConstant() {
|
|
100
|
-
try {
|
|
101
|
-
return this.status === 200 ? "SUCCESS" : constantCase(String(statuses(this.status)));
|
|
102
|
-
} catch (er) {
|
|
103
|
-
return constantCase(nameOf(classOf(this)));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export class HTTPException extends Exception {}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {Exception} from "./Exception.js";
|
|
2
|
-
import {StatusFamily} from "./StatusFamily.js";
|
|
3
|
-
|
|
4
|
-
export class RedirectException extends Exception {
|
|
5
|
-
constructor(status: number, message: string, origin?: Error | string | any) {
|
|
6
|
-
super(Exception.validate(status, StatusFamily["3xx"]), message, origin);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {Exception} from "./Exception.js";
|
|
2
|
-
import {StatusFamily} from "./StatusFamily.js";
|
|
3
|
-
|
|
4
|
-
export class ServerException extends Exception {
|
|
5
|
-
constructor(status: number, message: string, origin?: Error | string | any) {
|
|
6
|
-
super(Exception.validate(status, StatusFamily["5xx"]), message, origin);
|
|
7
|
-
}
|
|
8
|
-
}
|
package/src/core/StatusFamily.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by @tsed/barrels.
|
|
3
|
-
*/
|
|
4
|
-
export * from "./clientErrors/BadMapping.js";
|
|
5
|
-
export * from "./clientErrors/BadRequest.js";
|
|
6
|
-
export * from "./clientErrors/Conflict.js";
|
|
7
|
-
export * from "./clientErrors/ExpectationFailed.js";
|
|
8
|
-
export * from "./clientErrors/Forbidden.js";
|
|
9
|
-
export * from "./clientErrors/Gone.js";
|
|
10
|
-
export * from "./clientErrors/ImATeapot.js";
|
|
11
|
-
export * from "./clientErrors/LengthRequired.js";
|
|
12
|
-
export * from "./clientErrors/MethodNotAllowed.js";
|
|
13
|
-
export * from "./clientErrors/MisdirectedRequest.js";
|
|
14
|
-
export * from "./clientErrors/NotAcceptable.js";
|
|
15
|
-
export * from "./clientErrors/NotFound.js";
|
|
16
|
-
export * from "./clientErrors/PaymentRequired.js";
|
|
17
|
-
export * from "./clientErrors/PreconditionFailed.js";
|
|
18
|
-
export * from "./clientErrors/PreconditionRequired.js";
|
|
19
|
-
export * from "./clientErrors/ProxyAuthentificationRequired.js";
|
|
20
|
-
export * from "./clientErrors/RequestEntityTooLarge.js";
|
|
21
|
-
export * from "./clientErrors/RequestHeaderFieldsTooLarge.js";
|
|
22
|
-
export * from "./clientErrors/RequestRangeUnsatisfiable.js";
|
|
23
|
-
export * from "./clientErrors/RequestTimeout.js";
|
|
24
|
-
export * from "./clientErrors/RequestURITooLong.js";
|
|
25
|
-
export * from "./clientErrors/TooManyRequests.js";
|
|
26
|
-
export * from "./clientErrors/Unauthorized.js";
|
|
27
|
-
export * from "./clientErrors/UnavailableForLegalReasons.js";
|
|
28
|
-
export * from "./clientErrors/UnprocessableEntity.js";
|
|
29
|
-
export * from "./clientErrors/UnsupportedMediaType.js";
|
|
30
|
-
export * from "./clientErrors/UpgradeRequired.js";
|
|
31
|
-
export * from "./core/ClientException.js";
|
|
32
|
-
export * from "./core/Exception.js";
|
|
33
|
-
export * from "./core/RedirectException.js";
|
|
34
|
-
export * from "./core/ServerException.js";
|
|
35
|
-
export * from "./core/StatusFamily.js";
|
|
36
|
-
export * from "./redirections/MovedPermanently.js";
|
|
37
|
-
export * from "./redirections/MovedTemporarily.js";
|
|
38
|
-
export * from "./redirections/MultipleChoices.js";
|
|
39
|
-
export * from "./redirections/NotModified.js";
|
|
40
|
-
export * from "./redirections/PermanentRedirect.js";
|
|
41
|
-
export * from "./redirections/SeeOther.js";
|
|
42
|
-
export * from "./redirections/TemporaryRedirect.js";
|
|
43
|
-
export * from "./redirections/UseProxy.js";
|
|
44
|
-
export * from "./serverErrors/BadGateway.js";
|
|
45
|
-
export * from "./serverErrors/BandwidthLimitExceeded.js";
|
|
46
|
-
export * from "./serverErrors/GatewayTimeout.js";
|
|
47
|
-
export * from "./serverErrors/InternalServerError.js";
|
|
48
|
-
export * from "./serverErrors/NetworkAuthenticationRequired.js";
|
|
49
|
-
export * from "./serverErrors/NotExtended.js";
|
|
50
|
-
export * from "./serverErrors/NotImplemented.js";
|
|
51
|
-
export * from "./serverErrors/ProxyError.js";
|
|
52
|
-
export * from "./serverErrors/ServiceUnavailable.js";
|
|
53
|
-
export * from "./serverErrors/VariantAlsoNegotiates.js";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class MovedPermanently extends RedirectException {
|
|
4
|
-
static readonly STATUS = 301;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(MovedPermanently.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class MovedTemporarily extends RedirectException {
|
|
4
|
-
static readonly STATUS = 302;
|
|
5
|
-
name: string = "MOVED_TEMPORARILY";
|
|
6
|
-
|
|
7
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
8
|
-
super(MovedTemporarily.STATUS, message, origin);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class MultipleChoices extends RedirectException {
|
|
4
|
-
static readonly STATUS = 300;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(MultipleChoices.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class NotModified extends RedirectException {
|
|
4
|
-
static readonly STATUS = 304;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(NotModified.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class PermanentRedirect extends RedirectException {
|
|
4
|
-
static readonly STATUS = 308;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(PermanentRedirect.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class SeeOther extends RedirectException {
|
|
4
|
-
static readonly STATUS = 303;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(SeeOther.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class TemporaryRedirect extends RedirectException {
|
|
4
|
-
static readonly STATUS = 307;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(TemporaryRedirect.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {RedirectException} from "../core/RedirectException.js";
|
|
2
|
-
|
|
3
|
-
export class UseProxy extends RedirectException {
|
|
4
|
-
static readonly STATUS = 305;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(UseProxy.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ServerException} from "../core/ServerException.js";
|
|
2
|
-
|
|
3
|
-
export class BadGateway extends ServerException {
|
|
4
|
-
static readonly STATUS = 502;
|
|
5
|
-
|
|
6
|
-
constructor(message: string, origin?: Error | string | any) {
|
|
7
|
-
super(BadGateway.STATUS, message, origin);
|
|
8
|
-
}
|
|
9
|
-
}
|