@twin.org/api-models 0.0.3-next.21 → 0.0.3-next.22

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.
Files changed (81) hide show
  1. package/dist/es/errors/forbiddenError.js +23 -0
  2. package/dist/es/errors/forbiddenError.js.map +1 -0
  3. package/dist/es/errors/tooManyRequestsError.js +25 -0
  4. package/dist/es/errors/tooManyRequestsError.js.map +1 -0
  5. package/dist/es/helpers/httpErrorHelper.js +6 -2
  6. package/dist/es/helpers/httpErrorHelper.js.map +1 -1
  7. package/dist/es/index.js +4 -0
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/models/responses/errors/IConflictResponse.js.map +1 -1
  10. package/dist/es/models/responses/errors/INotImplementedResponse.js +2 -0
  11. package/dist/es/models/responses/errors/INotImplementedResponse.js.map +1 -0
  12. package/dist/es/models/responses/errors/ITooManyRequestsResponse.js +2 -0
  13. package/dist/es/models/responses/errors/ITooManyRequestsResponse.js.map +1 -0
  14. package/dist/types/errors/forbiddenError.d.ts +20 -0
  15. package/dist/types/errors/tooManyRequestsError.d.ts +22 -0
  16. package/dist/types/index.d.ts +4 -0
  17. package/dist/types/models/responses/errors/IConflictResponse.d.ts +1 -6
  18. package/dist/types/models/responses/errors/INotImplementedResponse.d.ts +15 -0
  19. package/dist/types/models/responses/errors/ITooManyRequestsResponse.d.ts +15 -0
  20. package/docs/changelog.md +7 -0
  21. package/docs/reference/classes/ForbiddenError.md +55 -0
  22. package/docs/reference/classes/HttpErrorHelper.md +3 -3
  23. package/docs/reference/classes/HttpParameterHelper.md +4 -4
  24. package/docs/reference/classes/HttpUrlHelper.md +6 -6
  25. package/docs/reference/classes/TooManyRequestsError.md +67 -0
  26. package/docs/reference/index.md +4 -0
  27. package/docs/reference/interfaces/IAcceptedResponse.md +2 -2
  28. package/docs/reference/interfaces/IBadRequestResponse.md +2 -2
  29. package/docs/reference/interfaces/IBaseRestClientConfig.md +9 -9
  30. package/docs/reference/interfaces/IBaseRoute.md +12 -12
  31. package/docs/reference/interfaces/IBaseRouteEntryPoint.md +4 -4
  32. package/docs/reference/interfaces/IBaseRouteProcessor.md +7 -7
  33. package/docs/reference/interfaces/IBaseSocketClientConfig.md +7 -7
  34. package/docs/reference/interfaces/IConflictResponse.md +3 -11
  35. package/docs/reference/interfaces/ICreatedResponse.md +2 -2
  36. package/docs/reference/interfaces/IForbiddenResponse.md +2 -2
  37. package/docs/reference/interfaces/IHealthComponentInfo.md +4 -4
  38. package/docs/reference/interfaces/IHealthInfo.md +3 -3
  39. package/docs/reference/interfaces/IHostingComponent.md +3 -3
  40. package/docs/reference/interfaces/IHttpRequest.md +8 -8
  41. package/docs/reference/interfaces/IHttpRequestContext.md +6 -6
  42. package/docs/reference/interfaces/IHttpRequestPathParams.md +1 -1
  43. package/docs/reference/interfaces/IHttpRequestQuery.md +1 -1
  44. package/docs/reference/interfaces/IHttpResponse.md +6 -6
  45. package/docs/reference/interfaces/IHttpServerRequest.md +11 -11
  46. package/docs/reference/interfaces/IInformationComponent.md +8 -8
  47. package/docs/reference/interfaces/IInternalServerErrorResponse.md +2 -2
  48. package/docs/reference/interfaces/IMimeTypeProcessor.md +2 -2
  49. package/docs/reference/interfaces/INoContentRequest.md +8 -8
  50. package/docs/reference/interfaces/INoContentResponse.md +1 -1
  51. package/docs/reference/interfaces/INotFoundResponse.md +3 -3
  52. package/docs/reference/interfaces/INotImplementedResponse.md +19 -0
  53. package/docs/reference/interfaces/IOkResponse.md +1 -1
  54. package/docs/reference/interfaces/IRestRoute.md +26 -26
  55. package/docs/reference/interfaces/IRestRouteExample.md +3 -3
  56. package/docs/reference/interfaces/IRestRouteProcessor.md +10 -10
  57. package/docs/reference/interfaces/IRestRouteRequestExample.md +4 -4
  58. package/docs/reference/interfaces/IRestRouteResponseAttachmentOptions.md +6 -6
  59. package/docs/reference/interfaces/IRestRouteResponseExample.md +4 -4
  60. package/docs/reference/interfaces/IRestRouteResponseOptions.md +2 -2
  61. package/docs/reference/interfaces/IServerFavIconResponse.md +7 -7
  62. package/docs/reference/interfaces/IServerHealthResponse.md +1 -1
  63. package/docs/reference/interfaces/IServerInfo.md +2 -2
  64. package/docs/reference/interfaces/IServerInfoResponse.md +1 -1
  65. package/docs/reference/interfaces/IServerLivezResponse.md +2 -2
  66. package/docs/reference/interfaces/IServerRootResponse.md +2 -2
  67. package/docs/reference/interfaces/IServerSpecResponse.md +4 -4
  68. package/docs/reference/interfaces/ISocketRequestContext.md +7 -7
  69. package/docs/reference/interfaces/ISocketRoute.md +17 -17
  70. package/docs/reference/interfaces/ISocketRouteProcessor.md +16 -16
  71. package/docs/reference/interfaces/ISocketServerRequest.md +12 -12
  72. package/docs/reference/interfaces/ITag.md +2 -2
  73. package/docs/reference/interfaces/ITenant.md +8 -8
  74. package/docs/reference/interfaces/ITenantAdminComponent.md +7 -7
  75. package/docs/reference/interfaces/ITooManyRequestsResponse.md +19 -0
  76. package/docs/reference/interfaces/IUnauthorizedResponse.md +2 -2
  77. package/docs/reference/interfaces/IUnprocessableEntityResponse.md +2 -2
  78. package/docs/reference/interfaces/IWebServer.md +4 -4
  79. package/docs/reference/interfaces/IWebServerOptions.md +36 -12
  80. package/docs/reference/variables/HealthStatus.md +3 -3
  81. package/package.json +1 -1
@@ -0,0 +1,23 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError } from "@twin.org/core";
4
+ /**
5
+ * Class to handle errors which are triggered by forbidden actions.
6
+ */
7
+ export class ForbiddenError extends BaseError {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static CLASS_NAME = "ForbiddenError";
12
+ /**
13
+ * Create a new instance of ForbiddenError.
14
+ * @param source The source of the error.
15
+ * @param message The message as a code.
16
+ * @param properties Any additional information for the error.
17
+ * @param cause The cause of the error if we have wrapped another error.
18
+ */
19
+ constructor(source, message, properties, cause) {
20
+ super(ForbiddenError.CLASS_NAME, source, message, properties, cause);
21
+ }
22
+ }
23
+ //# sourceMappingURL=forbiddenError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forbiddenError.js","sourceRoot":"","sources":["../../../src/errors/forbiddenError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC5C;;OAEG;IACI,MAAM,CAAU,UAAU,oBAAoC;IAErE;;;;;;OAMG;IACH,YACC,MAAc,EACd,OAAe,EACf,UAAsC,EACtC,KAAe;QAEf,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to handle errors which are triggered by forbidden actions.\n */\nexport class ForbiddenError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ForbiddenError>();\n\n\t/**\n\t * Create a new instance of ForbiddenError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(ForbiddenError.CLASS_NAME, source, message, properties, cause);\n\t}\n}\n"]}
@@ -0,0 +1,25 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError } from "@twin.org/core";
4
+ /**
5
+ * Class to handle errors which are triggered by too many requests.
6
+ */
7
+ export class TooManyRequestsError extends BaseError {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static CLASS_NAME = "TooManyRequestsError";
12
+ /**
13
+ * Create a new instance of TooManyRequestsError.
14
+ * @param source The source of the error.
15
+ * @param message The message as a code.
16
+ * @param requestCount The current request count.
17
+ * @param nextRequestTime The time when the next request can be made, as date ISO string.
18
+ * @param properties Any additional information for the error.
19
+ * @param cause The cause of the error if we have wrapped another error.
20
+ */
21
+ constructor(source, message, requestCount, nextRequestTime, properties, cause) {
22
+ super(TooManyRequestsError.CLASS_NAME, source, message, { requestCount, nextRequestTime, ...properties }, cause);
23
+ }
24
+ }
25
+ //# sourceMappingURL=tooManyRequestsError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooManyRequestsError.js","sourceRoot":"","sources":["../../../src/errors/tooManyRequestsError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAClD;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;;;;;;OAQG;IACH,YACC,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,eAAuB,EACvB,UAAsC,EACtC,KAAe;QAEf,KAAK,CACJ,oBAAoB,CAAC,UAAU,EAC/B,MAAM,EACN,OAAO,EACP,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,EAChD,KAAK,CACL,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to handle errors which are triggered by too many requests.\n */\nexport class TooManyRequestsError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TooManyRequestsError>();\n\n\t/**\n\t * Create a new instance of TooManyRequestsError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param requestCount The current request count.\n\t * @param nextRequestTime The time when the next request can be made, as date ISO string.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\trequestCount: number,\n\t\tnextRequestTime: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(\n\t\t\tTooManyRequestsError.CLASS_NAME,\n\t\t\tsource,\n\t\t\tmessage,\n\t\t\t{ requestCount, nextRequestTime, ...properties },\n\t\t\tcause\n\t\t);\n\t}\n}\n"]}
@@ -2,6 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import { AlreadyExistsError, BaseError, ConflictError, GuardError, NotFoundError, NotImplementedError, UnauthorizedError, UnprocessableError, ValidationError } from "@twin.org/core";
4
4
  import { HeaderTypes, HttpStatusCode, MimeTypes } from "@twin.org/web";
5
+ import { ForbiddenError } from "../errors/forbiddenError.js";
6
+ import { TooManyRequestsError } from "../errors/tooManyRequestsError.js";
5
7
  /**
6
8
  * Class to help with processing http errors.
7
9
  */
@@ -16,8 +18,10 @@ export class HttpErrorHelper {
16
18
  [AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,
17
19
  [NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,
18
20
  [UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,
19
- [NotImplementedError.CLASS_NAME]: HttpStatusCode.forbidden,
20
- [UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity
21
+ [NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,
22
+ [UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,
23
+ [TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,
24
+ [ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden
21
25
  };
22
26
  /**
23
27
  * Process the errors from the routes.
@@ -1 +1 @@
1
- {"version":3,"file":"httpErrorHelper.js","sourceRoot":"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E,CAAC;YAC1B,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvD,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACpE,CAAC;YAED,yEAAyE;YACzE,IAAI,cAAc,KAAK,cAAc,CAAC,mBAAmB,EAAE,CAAC;gBAC3D,KAAK,MAAM,SAAS,IAAI,eAAe,CAAC,cAAc,EAAE,CAAC;oBACxD,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;wBAC9D,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;wBAC3D,MAAM;oBACP,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAErD,OAAO;YACN,KAAK,EAAE,WAAW;YAClB,cAAc;SACd,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAC1B,QAAuB,EACvB,KAAa,EACb,UAA0B;QAE1B,QAAQ,CAAC,OAAO,KAAK,EAAE,CAAC;QACxB,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC,IAAI,iBAAiB,CAAC;QAC/E,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAClC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tConflictError,\n\tGuardError,\n\ttype IError,\n\tNotFoundError,\n\tNotImplementedError,\n\tUnauthorizedError,\n\tUnprocessableError,\n\tValidationError\n} from \"@twin.org/core\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\nimport type { IHttpResponse } from \"../models/protocol/IHttpResponse.js\";\n\n/**\n * Class to help with processing http errors.\n */\nexport class HttpErrorHelper {\n\t/**\n\t * Mapping of error types to status codes.\n\t */\n\tpublic static readonly ERROR_TYPE_MAP: { [id: string]: HttpStatusCode } = {\n\t\t[GuardError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ConflictError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,\n\t\t[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,\n\t\t[NotImplementedError.CLASS_NAME]: HttpStatusCode.forbidden,\n\t\t[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity\n\t};\n\n\t/**\n\t * Process the errors from the routes.\n\t * @param err The error to process.\n\t * @param includeStack Should the stack be included in the error.\n\t * @returns The status code and additional error data.\n\t */\n\tpublic static processError(\n\t\terr: unknown,\n\t\tincludeStack?: boolean\n\t): {\n\t\terror: IError;\n\t\thttpStatusCode: HttpStatusCode;\n\t} {\n\t\tconst error: BaseError = BaseError.fromError(err);\n\n\t\t// If the error or any of its sub errors are of the specific\n\t\t// types then set the http response code accordingly\n\t\tconst flattened = BaseError.flatten(error);\n\n\t\tlet httpStatusCode: HttpStatusCode = HttpStatusCode.internalServerError;\n\n\t\t// First check the primary error, as we don't want to override that with a sub error\n\t\tif (flattened.length > 0) {\n\t\t\tconst primaryError = flattened[0];\n\t\t\tif (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {\n\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];\n\t\t\t}\n\n\t\t\t// The primary error is still internal server error, check the sub errors\n\t\t\tif (httpStatusCode === HttpStatusCode.internalServerError) {\n\t\t\t\tfor (const className in HttpErrorHelper.ERROR_TYPE_MAP) {\n\t\t\t\t\tif (flattened.some(e => BaseError.isErrorName(e, className))) {\n\t\t\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst returnError = error.toJsonObject(includeStack);\n\n\t\treturn {\n\t\t\terror: returnError,\n\t\t\thttpStatusCode\n\t\t};\n\t}\n\n\t/**\n\t * Build an error response.\n\t * @param response The response to build the error into.\n\t * @param error The error to build the response for.\n\t * @param statusCode The status code to use for the error.\n\t */\n\tpublic static buildResponse(\n\t\tresponse: IHttpResponse,\n\t\terror: IError,\n\t\tstatusCode: HttpStatusCode\n\t): void {\n\t\tresponse.headers ??= {};\n\t\tresponse.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;\n\t\tresponse.body = error;\n\t\tresponse.statusCode = statusCode;\n\t}\n}\n"]}
1
+ {"version":3,"file":"httpErrorHelper.js","sourceRoot":"","sources":["../../../src/helpers/httpErrorHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,UAAU,EAEV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAGzE;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,cAAc,GAAqC;QACzE,CAAC,UAAU,CAAC,UAAU,CA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C;gBAC3D,KAAK,MAAM,SAAS,IAAI,eAAe,CAAC,cAAc,EAAE,CAAC;oBACxD,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;wBAC9D,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;wBAC3D,MAAM;oBACP,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAErD,OAAO;YACN,KAAK,EAAE,WAAW;YAClB,cAAc;SACd,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAC1B,QAAuB,EACvB,KAAa,EACb,UAA0B;QAE1B,QAAQ,CAAC,OAAO,KAAK,EAAE,CAAC;QACxB,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC,IAAI,iBAAiB,CAAC;QAC/E,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAClC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tConflictError,\n\tGuardError,\n\ttype IError,\n\tNotFoundError,\n\tNotImplementedError,\n\tUnauthorizedError,\n\tUnprocessableError,\n\tValidationError\n} from \"@twin.org/core\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\nimport { ForbiddenError } from \"../errors/forbiddenError.js\";\nimport { TooManyRequestsError } from \"../errors/tooManyRequestsError.js\";\nimport type { IHttpResponse } from \"../models/protocol/IHttpResponse.js\";\n\n/**\n * Class to help with processing http errors.\n */\nexport class HttpErrorHelper {\n\t/**\n\t * Mapping of error types to status codes.\n\t */\n\tpublic static readonly ERROR_TYPE_MAP: { [id: string]: HttpStatusCode } = {\n\t\t[GuardError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ConflictError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,\n\t\t[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,\n\t\t[NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,\n\t\t[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,\n\t\t[TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,\n\t\t[ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden\n\t};\n\n\t/**\n\t * Process the errors from the routes.\n\t * @param err The error to process.\n\t * @param includeStack Should the stack be included in the error.\n\t * @returns The status code and additional error data.\n\t */\n\tpublic static processError(\n\t\terr: unknown,\n\t\tincludeStack?: boolean\n\t): {\n\t\terror: IError;\n\t\thttpStatusCode: HttpStatusCode;\n\t} {\n\t\tconst error: BaseError = BaseError.fromError(err);\n\n\t\t// If the error or any of its sub errors are of the specific\n\t\t// types then set the http response code accordingly\n\t\tconst flattened = BaseError.flatten(error);\n\n\t\tlet httpStatusCode: HttpStatusCode = HttpStatusCode.internalServerError;\n\n\t\t// First check the primary error, as we don't want to override that with a sub error\n\t\tif (flattened.length > 0) {\n\t\t\tconst primaryError = flattened[0];\n\t\t\tif (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {\n\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];\n\t\t\t}\n\n\t\t\t// The primary error is still internal server error, check the sub errors\n\t\t\tif (httpStatusCode === HttpStatusCode.internalServerError) {\n\t\t\t\tfor (const className in HttpErrorHelper.ERROR_TYPE_MAP) {\n\t\t\t\t\tif (flattened.some(e => BaseError.isErrorName(e, className))) {\n\t\t\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst returnError = error.toJsonObject(includeStack);\n\n\t\treturn {\n\t\t\terror: returnError,\n\t\t\thttpStatusCode\n\t\t};\n\t}\n\n\t/**\n\t * Build an error response.\n\t * @param response The response to build the error into.\n\t * @param error The error to build the response for.\n\t * @param statusCode The status code to use for the error.\n\t */\n\tpublic static buildResponse(\n\t\tresponse: IHttpResponse,\n\t\terror: IError,\n\t\tstatusCode: HttpStatusCode\n\t): void {\n\t\tresponse.headers ??= {};\n\t\tresponse.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;\n\t\tresponse.body = error;\n\t\tresponse.statusCode = statusCode;\n\t}\n}\n"]}
package/dist/es/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./errors/forbiddenError.js";
4
+ export * from "./errors/tooManyRequestsError.js";
3
5
  export * from "./factories/mimeTypeProcessorFactory.js";
4
6
  export * from "./factories/restRouteProcessorFactory.js";
5
7
  export * from "./factories/socketRouteProcessorFactory.js";
@@ -28,6 +30,8 @@ export * from "./models/responses/errors/IConflictResponse.js";
28
30
  export * from "./models/responses/errors/IForbiddenResponse.js";
29
31
  export * from "./models/responses/errors/IInternalServerErrorResponse.js";
30
32
  export * from "./models/responses/errors/INotFoundResponse.js";
33
+ export * from "./models/responses/errors/INotImplementedResponse.js";
34
+ export * from "./models/responses/errors/ITooManyRequestsResponse.js";
31
35
  export * from "./models/responses/errors/IUnauthorizedResponse.js";
32
36
  export * from "./models/responses/errors/IUnprocessableEntityResponse.js";
33
37
  export * from "./models/responses/success/IAcceptedResponse.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","s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AAiC,CAAC;AAChD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./factories/mimeTypeProcessorFactory.js\";\nexport * from \"./factories/restRouteProcessorFactory.js\";\nexport * from \"./factories/socketRouteProcessorFactory.js\";\nexport * from \"./helpers/httpErrorHelper.js\";\nexport * from \"./helpers/httpParameterHelper.js\";\nexport * from \"./helpers/httpUrlHelper.js\";\nexport * from \"./models/api/IServerFavIconResponse.js\";\nexport * from \"./models/api/IServerHealthResponse.js\";\nexport * from \"./models/api/IServerInfoResponse.js\";\nexport * from \"./models/api/IServerLivezResponse.js\";\nexport * from \"./models/api/IServerRootResponse.js\";\nexport * from \"./models/api/IServerSpecResponse.js\";\nexport * from \"./models/config/IBaseRestClientConfig.js\";\nexport * from \"./models/config/IBaseSocketClientConfig.js\";\nexport * from \"./models/protocol/IHttpRequest.js\";\nexport * from \"./models/protocol/IHttpRequestContext.js\";\nexport * from \"./models/protocol/IHttpRequestPathParams.js\";\nexport * from \"./models/protocol/IHttpRequestQuery.js\";\nexport * from \"./models/protocol/IHttpResponse.js\";\nexport * from \"./models/protocol/IHttpServerRequest.js\";\nexport * from \"./models/protocol/ISocketRequestContext.js\";\nexport * from \"./models/protocol/ISocketServerRequest.js\";\nexport * from \"./models/requests/INoContentRequest.js\";\nexport * from \"./models/responses/errors/IBadRequestResponse.js\";\nexport * from \"./models/responses/errors/IConflictResponse.js\";\nexport * from \"./models/responses/errors/IForbiddenResponse.js\";\nexport * from \"./models/responses/errors/IInternalServerErrorResponse.js\";\nexport * from \"./models/responses/errors/INotFoundResponse.js\";\nexport * from \"./models/responses/errors/IUnauthorizedResponse.js\";\nexport * from \"./models/responses/errors/IUnprocessableEntityResponse.js\";\nexport * from \"./models/responses/success/IAcceptedResponse.js\";\nexport * from \"./models/responses/success/ICreatedResponse.js\";\nexport * from \"./models/responses/success/INoContentResponse.js\";\nexport * from \"./models/responses/success/IOkResponse.js\";\nexport * from \"./models/routes/IBaseRoute.js\";\nexport * from \"./models/routes/IBaseRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRoute.js\";\nexport * from \"./models/routes/IRestRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRouteExample.js\";\nexport * from \"./models/routes/IRestRouteRequestExample.js\";\nexport * from \"./models/routes/IRestRouteResponseAttachmentOptions.js\";\nexport * from \"./models/routes/IRestRouteResponseExample.js\";\nexport * from \"./models/routes/IRestRouteResponseOptions.js\";\nexport * from \"./models/routes/ISocketRoute.js\";\nexport * from \"./models/routes/ISocketRouteEntryPoint.js\";\nexport * from \"./models/routes/ITag.js\";\nexport * from \"./models/server/IBaseRouteProcessor.js\";\nexport * from \"./models/server/IMimeTypeProcessor.js\";\nexport * from \"./models/server/IRestRouteProcessor.js\";\nexport * from \"./models/server/ISocketRouteProcessor.js\";\nexport * from \"./models/server/IWebServer.js\";\nexport * from \"./models/server/IWebServerOptions.js\";\nexport * from \"./models/services/healthStatus.js\";\nexport * from \"./models/services/IHealthComponentInfo.js\";\nexport * from \"./models/services/IHealthInfo.js\";\nexport * from \"./models/services/IHostingComponent.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IServerInfo.js\";\nexport * from \"./models/services/ITenant.js\";\nexport * from \"./models/services/ITenantAdminComponent.js\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ACxD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,iCAAiC,CAAC;AAChD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./errors/forbiddenError.js\";\nexport * from \"./errors/tooManyRequestsError.js\";\nexport * from \"./factories/mimeTypeProcessorFactory.js\";\nexport * from \"./factories/restRouteProcessorFactory.js\";\nexport * from \"./factories/socketRouteProcessorFactory.js\";\nexport * from \"./helpers/httpErrorHelper.js\";\nexport * from \"./helpers/httpParameterHelper.js\";\nexport * from \"./helpers/httpUrlHelper.js\";\nexport * from \"./models/api/IServerFavIconResponse.js\";\nexport * from \"./models/api/IServerHealthResponse.js\";\nexport * from \"./models/api/IServerInfoResponse.js\";\nexport * from \"./models/api/IServerLivezResponse.js\";\nexport * from \"./models/api/IServerRootResponse.js\";\nexport * from \"./models/api/IServerSpecResponse.js\";\nexport * from \"./models/config/IBaseRestClientConfig.js\";\nexport * from \"./models/config/IBaseSocketClientConfig.js\";\nexport * from \"./models/protocol/IHttpRequest.js\";\nexport * from \"./models/protocol/IHttpRequestContext.js\";\nexport * from \"./models/protocol/IHttpRequestPathParams.js\";\nexport * from \"./models/protocol/IHttpRequestQuery.js\";\nexport * from \"./models/protocol/IHttpResponse.js\";\nexport * from \"./models/protocol/IHttpServerRequest.js\";\nexport * from \"./models/protocol/ISocketRequestContext.js\";\nexport * from \"./models/protocol/ISocketServerRequest.js\";\nexport * from \"./models/requests/INoContentRequest.js\";\nexport * from \"./models/responses/errors/IBadRequestResponse.js\";\nexport * from \"./models/responses/errors/IConflictResponse.js\";\nexport * from \"./models/responses/errors/IForbiddenResponse.js\";\nexport * from \"./models/responses/errors/IInternalServerErrorResponse.js\";\nexport * from \"./models/responses/errors/INotFoundResponse.js\";\nexport * from \"./models/responses/errors/INotImplementedResponse.js\";\nexport * from \"./models/responses/errors/ITooManyRequestsResponse.js\";\nexport * from \"./models/responses/errors/IUnauthorizedResponse.js\";\nexport * from \"./models/responses/errors/IUnprocessableEntityResponse.js\";\nexport * from \"./models/responses/success/IAcceptedResponse.js\";\nexport * from \"./models/responses/success/ICreatedResponse.js\";\nexport * from \"./models/responses/success/INoContentResponse.js\";\nexport * from \"./models/responses/success/IOkResponse.js\";\nexport * from \"./models/routes/IBaseRoute.js\";\nexport * from \"./models/routes/IBaseRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRoute.js\";\nexport * from \"./models/routes/IRestRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRouteExample.js\";\nexport * from \"./models/routes/IRestRouteRequestExample.js\";\nexport * from \"./models/routes/IRestRouteResponseAttachmentOptions.js\";\nexport * from \"./models/routes/IRestRouteResponseExample.js\";\nexport * from \"./models/routes/IRestRouteResponseOptions.js\";\nexport * from \"./models/routes/ISocketRoute.js\";\nexport * from \"./models/routes/ISocketRouteEntryPoint.js\";\nexport * from \"./models/routes/ITag.js\";\nexport * from \"./models/server/IBaseRouteProcessor.js\";\nexport * from \"./models/server/IMimeTypeProcessor.js\";\nexport * from \"./models/server/IRestRouteProcessor.js\";\nexport * from \"./models/server/ISocketRouteProcessor.js\";\nexport * from \"./models/server/IWebServer.js\";\nexport * from \"./models/server/IWebServerOptions.js\";\nexport * from \"./models/services/healthStatus.js\";\nexport * from \"./models/services/IHealthComponentInfo.js\";\nexport * from \"./models/services/IHealthInfo.js\";\nexport * from \"./models/services/IHostingComponent.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IServerInfo.js\";\nexport * from \"./models/services/ITenant.js\";\nexport * from \"./models/services/ITenantAdminComponent.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IConflictResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/IConflictResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in a conflicting operation, see the content for more details.\n */\nexport interface IConflictResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.conflict;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError & {\n\t\t/**\n\t\t * The conflicting items.\n\t\t */\n\t\tconflicts: string[];\n\t};\n}\n"]}
1
+ {"version":3,"file":"IConflictResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/IConflictResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in a conflicting operation, see the content for more details.\n */\nexport interface IConflictResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.conflict;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=INotImplementedResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"INotImplementedResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/INotImplementedResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The operation that you tried to perform is not implemented, see the content for more details.\n */\nexport interface INotImplementedResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.notImplemented;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITooManyRequestsResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITooManyRequestsResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/ITooManyRequestsResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in too many requests, see the content for more details.\n */\nexport interface ITooManyRequestsResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.tooManyRequests;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { BaseError } from "@twin.org/core";
2
+ /**
3
+ * Class to handle errors which are triggered by forbidden actions.
4
+ */
5
+ export declare class ForbiddenError extends BaseError {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * Create a new instance of ForbiddenError.
12
+ * @param source The source of the error.
13
+ * @param message The message as a code.
14
+ * @param properties Any additional information for the error.
15
+ * @param cause The cause of the error if we have wrapped another error.
16
+ */
17
+ constructor(source: string, message: string, properties?: {
18
+ [id: string]: unknown;
19
+ }, cause?: unknown);
20
+ }
@@ -0,0 +1,22 @@
1
+ import { BaseError } from "@twin.org/core";
2
+ /**
3
+ * Class to handle errors which are triggered by too many requests.
4
+ */
5
+ export declare class TooManyRequestsError extends BaseError {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * Create a new instance of TooManyRequestsError.
12
+ * @param source The source of the error.
13
+ * @param message The message as a code.
14
+ * @param requestCount The current request count.
15
+ * @param nextRequestTime The time when the next request can be made, as date ISO string.
16
+ * @param properties Any additional information for the error.
17
+ * @param cause The cause of the error if we have wrapped another error.
18
+ */
19
+ constructor(source: string, message: string, requestCount: number, nextRequestTime: string, properties?: {
20
+ [id: string]: unknown;
21
+ }, cause?: unknown);
22
+ }
@@ -1,3 +1,5 @@
1
+ export * from "./errors/forbiddenError.js";
2
+ export * from "./errors/tooManyRequestsError.js";
1
3
  export * from "./factories/mimeTypeProcessorFactory.js";
2
4
  export * from "./factories/restRouteProcessorFactory.js";
3
5
  export * from "./factories/socketRouteProcessorFactory.js";
@@ -26,6 +28,8 @@ export * from "./models/responses/errors/IConflictResponse.js";
26
28
  export * from "./models/responses/errors/IForbiddenResponse.js";
27
29
  export * from "./models/responses/errors/IInternalServerErrorResponse.js";
28
30
  export * from "./models/responses/errors/INotFoundResponse.js";
31
+ export * from "./models/responses/errors/INotImplementedResponse.js";
32
+ export * from "./models/responses/errors/ITooManyRequestsResponse.js";
29
33
  export * from "./models/responses/errors/IUnauthorizedResponse.js";
30
34
  export * from "./models/responses/errors/IUnprocessableEntityResponse.js";
31
35
  export * from "./models/responses/success/IAcceptedResponse.js";
@@ -11,10 +11,5 @@ export interface IConflictResponse {
11
11
  /**
12
12
  * The body which contains the error.
13
13
  */
14
- body: IError & {
15
- /**
16
- * The conflicting items.
17
- */
18
- conflicts: string[];
19
- };
14
+ body: IError;
20
15
  }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The operation that you tried to perform is not implemented, see the content for more details.
5
+ */
6
+ export interface INotImplementedResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.notImplemented;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { IError } from "@twin.org/core";
2
+ import type { HttpStatusCode } from "@twin.org/web";
3
+ /**
4
+ * The request resulted in too many requests, see the content for more details.
5
+ */
6
+ export interface ITooManyRequestsResponse {
7
+ /**
8
+ * Response status code.
9
+ */
10
+ statusCode: typeof HttpStatusCode.tooManyRequests;
11
+ /**
12
+ * The body which contains the error.
13
+ */
14
+ body: IError;
15
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.22](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.21...api-models-v0.0.3-next.22) (2026-03-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * add new error types ([#86](https://github.com/twinfoundation/api/issues/86)) ([71e3c07](https://github.com/twinfoundation/api/commit/71e3c07c792984af01c307943e0e09a3ae98710d))
9
+
3
10
  ## [0.0.3-next.21](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.20...api-models-v0.0.3-next.21) (2026-03-11)
4
11
 
5
12
 
@@ -0,0 +1,55 @@
1
+ # Class: ForbiddenError
2
+
3
+ Class to handle errors which are triggered by forbidden actions.
4
+
5
+ ## Extends
6
+
7
+ - `BaseError`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new ForbiddenError**(`source`, `message`, `properties?`, `cause?`): `ForbiddenError`
14
+
15
+ Create a new instance of ForbiddenError.
16
+
17
+ #### Parameters
18
+
19
+ ##### source
20
+
21
+ `string`
22
+
23
+ The source of the error.
24
+
25
+ ##### message
26
+
27
+ `string`
28
+
29
+ The message as a code.
30
+
31
+ ##### properties?
32
+
33
+ Any additional information for the error.
34
+
35
+ ##### cause?
36
+
37
+ `unknown`
38
+
39
+ The cause of the error if we have wrapped another error.
40
+
41
+ #### Returns
42
+
43
+ `ForbiddenError`
44
+
45
+ #### Overrides
46
+
47
+ `BaseError.constructor`
48
+
49
+ ## Properties
50
+
51
+ ### CLASS\_NAME {#class_name}
52
+
53
+ > `readonly` `static` **CLASS\_NAME**: `string`
54
+
55
+ Runtime name for the class.
@@ -14,7 +14,7 @@ Class to help with processing http errors.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### ERROR\_TYPE\_MAP
17
+ ### ERROR\_TYPE\_MAP {#error_type_map}
18
18
 
19
19
  > `readonly` `static` **ERROR\_TYPE\_MAP**: `object`
20
20
 
@@ -26,7 +26,7 @@ Mapping of error types to status codes.
26
26
 
27
27
  ## Methods
28
28
 
29
- ### processError()
29
+ ### processError() {#processerror}
30
30
 
31
31
  > `static` **processError**(`err`, `includeStack?`): `object`
32
32
 
@@ -62,7 +62,7 @@ The status code and additional error data.
62
62
 
63
63
  ***
64
64
 
65
- ### buildResponse()
65
+ ### buildResponse() {#buildresponse}
66
66
 
67
67
  > `static` **buildResponse**(`response`, `error`, `statusCode`): `void`
68
68
 
@@ -14,7 +14,7 @@ Class to help with handling http parameters.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### arrayFromString()
17
+ ### arrayFromString() {#arrayfromstring}
18
18
 
19
19
  > `static` **arrayFromString**\<`T`\>(`values?`): `T`[] \| `undefined`
20
20
 
@@ -42,7 +42,7 @@ The array of values.
42
42
 
43
43
  ***
44
44
 
45
- ### arrayToString()
45
+ ### arrayToString() {#arraytostring}
46
46
 
47
47
  > `static` **arrayToString**\<`T`\>(`values?`): `string` \| `undefined`
48
48
 
@@ -70,7 +70,7 @@ The combined.
70
70
 
71
71
  ***
72
72
 
73
- ### objectFromString()
73
+ ### objectFromString() {#objectfromstring}
74
74
 
75
75
  > `static` **objectFromString**\<`T`\>(`value?`): `T` \| `undefined`
76
76
 
@@ -98,7 +98,7 @@ The object.
98
98
 
99
99
  ***
100
100
 
101
- ### objectToString()
101
+ ### objectToString() {#objecttostring}
102
102
 
103
103
  > `static` **objectToString**\<`T`\>(`value?`): `string` \| `undefined`
104
104
 
@@ -14,7 +14,7 @@ Class to help with handling http URLs.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### extractOrigin()
17
+ ### extractOrigin() {#extractorigin}
18
18
 
19
19
  > `static` **extractOrigin**(`url`): `string` \| `undefined`
20
20
 
@@ -40,7 +40,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/origin
40
40
 
41
41
  ***
42
42
 
43
- ### extractPath()
43
+ ### extractPath() {#extractpath}
44
44
 
45
45
  > `static` **extractPath**(`url`): `string` \| `undefined`
46
46
 
@@ -66,7 +66,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
66
66
 
67
67
  ***
68
68
 
69
- ### extractSearch()
69
+ ### extractSearch() {#extractsearch}
70
70
 
71
71
  > `static` **extractSearch**(`url`): `string` \| `undefined`
72
72
 
@@ -92,7 +92,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/search
92
92
 
93
93
  ***
94
94
 
95
- ### extractPathAndSearch()
95
+ ### extractPathAndSearch() {#extractpathandsearch}
96
96
 
97
97
  > `static` **extractPathAndSearch**(`url`): `string` \| `undefined`
98
98
 
@@ -114,7 +114,7 @@ The extracted path and search.
114
114
 
115
115
  ***
116
116
 
117
- ### combineParts()
117
+ ### combineParts() {#combineparts}
118
118
 
119
119
  > `static` **combineParts**(`origin`, `pathAndSearch`): `string` \| `undefined`
120
120
 
@@ -142,7 +142,7 @@ The combined parts.
142
142
 
143
143
  ***
144
144
 
145
- ### replaceOrigin()
145
+ ### replaceOrigin() {#replaceorigin}
146
146
 
147
147
  > `static` **replaceOrigin**(`url`, `newOrigin?`): `string`
148
148
 
@@ -0,0 +1,67 @@
1
+ # Class: TooManyRequestsError
2
+
3
+ Class to handle errors which are triggered by too many requests.
4
+
5
+ ## Extends
6
+
7
+ - `BaseError`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new TooManyRequestsError**(`source`, `message`, `requestCount`, `nextRequestTime`, `properties?`, `cause?`): `TooManyRequestsError`
14
+
15
+ Create a new instance of TooManyRequestsError.
16
+
17
+ #### Parameters
18
+
19
+ ##### source
20
+
21
+ `string`
22
+
23
+ The source of the error.
24
+
25
+ ##### message
26
+
27
+ `string`
28
+
29
+ The message as a code.
30
+
31
+ ##### requestCount
32
+
33
+ `number`
34
+
35
+ The current request count.
36
+
37
+ ##### nextRequestTime
38
+
39
+ `string`
40
+
41
+ The time when the next request can be made, as date ISO string.
42
+
43
+ ##### properties?
44
+
45
+ Any additional information for the error.
46
+
47
+ ##### cause?
48
+
49
+ `unknown`
50
+
51
+ The cause of the error if we have wrapped another error.
52
+
53
+ #### Returns
54
+
55
+ `TooManyRequestsError`
56
+
57
+ #### Overrides
58
+
59
+ `BaseError.constructor`
60
+
61
+ ## Properties
62
+
63
+ ### CLASS\_NAME {#class_name}
64
+
65
+ > `readonly` `static` **CLASS\_NAME**: `string`
66
+
67
+ Runtime name for the class.
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Classes
4
4
 
5
+ - [ForbiddenError](classes/ForbiddenError.md)
6
+ - [TooManyRequestsError](classes/TooManyRequestsError.md)
5
7
  - [HttpErrorHelper](classes/HttpErrorHelper.md)
6
8
  - [HttpParameterHelper](classes/HttpParameterHelper.md)
7
9
  - [HttpUrlHelper](classes/HttpUrlHelper.md)
@@ -30,6 +32,8 @@
30
32
  - [IForbiddenResponse](interfaces/IForbiddenResponse.md)
31
33
  - [IInternalServerErrorResponse](interfaces/IInternalServerErrorResponse.md)
32
34
  - [INotFoundResponse](interfaces/INotFoundResponse.md)
35
+ - [INotImplementedResponse](interfaces/INotImplementedResponse.md)
36
+ - [ITooManyRequestsResponse](interfaces/ITooManyRequestsResponse.md)
33
37
  - [IUnauthorizedResponse](interfaces/IUnauthorizedResponse.md)
34
38
  - [IUnprocessableEntityResponse](interfaces/IUnprocessableEntityResponse.md)
35
39
  - [IAcceptedResponse](interfaces/IAcceptedResponse.md)
@@ -4,7 +4,7 @@ The rest request ended in accepted response.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### statusCode
7
+ ### statusCode {#statuscode}
8
8
 
9
9
  > **statusCode**: `202`
10
10
 
@@ -12,7 +12,7 @@ Response status code.
12
12
 
13
13
  ***
14
14
 
15
- ### headers
15
+ ### headers {#headers}
16
16
 
17
17
  > **headers**: `object`
18
18
 
@@ -4,7 +4,7 @@ The server cannot process the request, see the content for more details.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### statusCode
7
+ ### statusCode {#statuscode}
8
8
 
9
9
  > **statusCode**: `400`
10
10
 
@@ -12,7 +12,7 @@ Response status code.
12
12
 
13
13
  ***
14
14
 
15
- ### body
15
+ ### body {#body}
16
16
 
17
17
  > **body**: `IError`
18
18
 
@@ -4,7 +4,7 @@ Definition for the configuration of a rest client.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### endpoint
7
+ ### endpoint {#endpoint}
8
8
 
9
9
  > **endpoint**: `string`
10
10
 
@@ -12,32 +12,32 @@ The endpoint where the api is hosted.
12
12
 
13
13
  ***
14
14
 
15
- ### pathPrefix?
15
+ ### pathPrefix? {#pathprefix}
16
16
 
17
- > `optional` **pathPrefix**: `string`
17
+ > `optional` **pathPrefix?**: `string`
18
18
 
19
19
  The prefix to the routes.
20
20
 
21
21
  ***
22
22
 
23
- ### headers?
23
+ ### headers? {#headers}
24
24
 
25
- > `optional` **headers**: `IHttpHeaders`
25
+ > `optional` **headers?**: `IHttpHeaders`
26
26
 
27
27
  The headers to include in requests.
28
28
 
29
29
  ***
30
30
 
31
- ### timeout?
31
+ ### timeout? {#timeout}
32
32
 
33
- > `optional` **timeout**: `number`
33
+ > `optional` **timeout?**: `number`
34
34
 
35
35
  Timeout for requests in ms.
36
36
 
37
37
  ***
38
38
 
39
- ### includeCredentials?
39
+ ### includeCredentials? {#includecredentials}
40
40
 
41
- > `optional` **includeCredentials**: `boolean`
41
+ > `optional` **includeCredentials?**: `boolean`
42
42
 
43
43
  Include credentials in the request, defaults to true.