TLDR: how do I customize the "Error occurred while trying to proxy: localhost:3000/" in http-proxy-middleware
?
I'm using the node package http-proxy-middleware
as a proxy.
I have some patterns where I know that the proxying will fail. Here is a minimal example of what happens:
const { createProxyMiddleware } = require('http-proxy-middleware');
require('express')().use(
'/',
createProxyMiddleware({
target: 'http://failhtis/'
})
).listen(3000);
This will display this in my browser :
And in my console :
[HPM] Error occurred while proxying request localhost:3000/ to http://failhtis/ [ENOTFOUND] (https://nodejs.org/api/errors.html#errors_common_system_errors)
What I would love to do is generate a custom message / html for the error. How do I manage that?
I've tried the ejectPlugin
method described here : https://github.com/chimurai/http-proxy-middleware#ejectplugins-boolean-default-false but without success.
To sum up: I know error will happen in my setup, how do I send a custom answer instead of the "Error occured while proxying..." message?