1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var status_error_1 = require("./status-error");
|
4 | exports.BLOCK_CHAIN = "__block_chain";
|
5 | /**
|
6 | * This class defines the base middleware class. Any middleware should be extends
|
7 | * this abstract class, implementing the apply method.
|
8 | */
|
9 | var BaseMiddleware = /** @class */ (function () {
|
10 | function BaseMiddleware(app) {
|
11 | this.app = app;
|
12 | }
|
13 | /**
|
14 | * Utility method to generate an error with a status code.
|
15 | * This method should be used instead of the usual throw new Error(msg).
|
16 | * In this way, a proper HTTP status code can be used (for example, 404 or 500),
|
17 | * instead of the default 400.
|
18 | * @param status the http status code to return
|
19 | * @param message the error message
|
20 | * @return a new @type StatusError object
|
21 | */
|
22 | BaseMiddleware.prototype.error = function (status, message) {
|
23 | var err = new status_error_1.default(message);
|
24 | err.statusCode = status;
|
25 | return err;
|
26 | };
|
27 | return BaseMiddleware;
|
28 | }());
|
29 | exports.BaseMiddleware = BaseMiddleware;
|