UNPKG

1.21 kBTypeScriptView Raw
1import * as express from "express";
2import App from "./app";
3import StatusError from "./status-error";
4export declare const 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 */
9export declare abstract class BaseMiddleware {
10 app: App;
11 constructor(app: App);
12 /**
13 * Utility method to generate an error with a status code.
14 * This method should be used instead of the usual throw new Error(msg).
15 * In this way, a proper HTTP status code can be used (for example, 404 or 500),
16 * instead of the default 400.
17 * @param status the http status code to return
18 * @param message the error message
19 * @return a new @type StatusError object
20 */
21 error(status: number, message: string): StatusError;
22 /**
23 * This method is automatically executed by the framework.
24 * @param req the standard express Request object
25 * @param res the standard express Response object
26 * @return to block the middlewares-controller chain, please return `BLOCK_CHAIN`
27 */
28 abstract apply(req: express.Request, res: express.Response): Promise<any>;
29}