Skip to content

Commit 26b9522

Browse files
ChosanChosan
Chosan
authored and
Chosan
committed
fix(devServer): support custom devServer proxy error handler
close vuejs#7456
1 parent f0f254e commit 26b9522

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: packages/@vue/cli-service/lib/util/prepareProxy.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
5454
return !(isPublicFileRequest || isWdsEndpointRequest)
5555
}
5656

57-
function createProxyEntry (target, usersOnProxyReq, context) {
57+
function createProxyEntry (target, usersOnProxyReq, usersOnError, context) {
5858
// #2478
5959
// There're a little-known use case that the `target` field is an object rather than a string
6060
// https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/https.md
@@ -97,7 +97,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
9797
proxyReq.setHeader('origin', target)
9898
}
9999
},
100-
onError: onProxyError(target)
100+
onError: usersOnError ? (err, req, res) => usersOnError(err, req, res, target) : onDefaultProxyError(target)
101101
}
102102
}
103103

@@ -129,7 +129,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
129129
)
130130
process.exit(1)
131131
}
132-
const entry = createProxyEntry(config.target, config.onProxyReq, context)
132+
const entry = createProxyEntry(config.target, config.onProxyReq, config.onError, context)
133133
return Object.assign({}, defaultConfig, config, entry)
134134
})
135135
}
@@ -163,9 +163,9 @@ function resolveLoopback (proxy) {
163163
return url.format(o)
164164
}
165165

166-
// We need to provide a custom onError function for httpProxyMiddleware.
166+
// We need to provide a default custom onError function for httpProxyMiddleware.
167167
// It allows us to log custom error messages on the console.
168-
function onProxyError (proxy) {
168+
function onDefaultProxyError (proxy) {
169169
return (err, req, res) => {
170170
const host = req.headers && req.headers.host
171171
console.log(

0 commit comments

Comments
 (0)