From 6a3064cc7408b4e71d0d0feb6f92457d4c22e15c Mon Sep 17 00:00:00 2001 From: Niek van Bennekom <37668320+niekvb@users.noreply.github.com> Date: Fri, 3 May 2019 23:46:25 +0200 Subject: [PATCH] Included definition for proxyErrorHandler in express-http-proxy (#35185) --- types/express-http-proxy/express-http-proxy-tests.ts | 10 ++++++++++ types/express-http-proxy/index.d.ts | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/express-http-proxy/express-http-proxy-tests.ts b/types/express-http-proxy/express-http-proxy-tests.ts index 6c628b3c49..e30cecbb03 100644 --- a/types/express-http-proxy/express-http-proxy-tests.ts +++ b/types/express-http-proxy/express-http-proxy-tests.ts @@ -19,6 +19,16 @@ proxy('www.google.com', { limit: 1024 }); +proxy('www.google.com', { + proxyErrorHandler: (err, res, next) => { + switch (err && err.code) { + case 'ECONNRESET': { return res.status(405).send('504 became 405'); } + case 'ECONNREFUSED': { return res.status(200).send('gotcher back'); } + default: { next(err); } + } + }, +}); + proxy('www.google.com', { proxyReqOptDecorator(proxyReqOpts, srcReq) { console.log(proxyReqOpts.headers, proxyReqOpts.method); diff --git a/types/express-http-proxy/index.d.ts b/types/express-http-proxy/index.d.ts index 6d1943fa9c..c8861af3ab 100644 --- a/types/express-http-proxy/index.d.ts +++ b/types/express-http-proxy/index.d.ts @@ -3,12 +3,13 @@ // Definitions by: ulrichb // Daniel Schopf // Gabriel Fournier +// Niek van Bennekom // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 import { RequestHandler, Request } from "express"; import { RequestOptions, IncomingHttpHeaders, OutgoingHttpHeaders } from "http"; -import { Response } from "express-serve-static-core"; +import { NextFunction, Response } from "express-serve-static-core"; interface ProxyOptions { /** @@ -17,6 +18,7 @@ interface ProxyOptions { * See https://github.com/stream-utils/raw-body/blob/master/index.d.ts */ limit?: number | string; + proxyErrorHandler?: (err: any, res: Response, next: NextFunction) => any; proxyReqPathResolver?: (req: Request) => string; proxyReqOptDecorator?: (proxyReqOpts: RequestOptions, srcReq: Request) => RequestOptions; userResHeaderDecorator?: (headers: IncomingHttpHeaders, userReq: Request, userRes: Response, proxyReq: Request, proxyRes: Response) => OutgoingHttpHeaders;