|
@@ -74,14 +74,17 @@ var proxyHandler = func(r *ghttp.Request) {
|
|
|
// 代理地址存入上下文ctx中
|
|
|
gCtx.ServerAddr = proxyAddr.String()
|
|
|
router.UpdateGContext(r, gCtx)
|
|
|
-
|
|
|
// 捕获异常,若代理出错,则进行重试
|
|
|
var hasErr bool
|
|
|
errHandel := func(hw http.ResponseWriter, hr *http.Request, err error) {
|
|
|
hasErr = true
|
|
|
+ if err.Error() == "context canceled" {
|
|
|
+ return
|
|
|
+ }
|
|
|
if i == (errTryTime - 1) {
|
|
|
r.SetError(NewErrorWithCode(GATEWAY_PROXY_ERR, fmt.Sprintf("代理异常:%s err:%v \n", gCtx.ServerAddr, err.Error())))
|
|
|
}
|
|
|
+ g.Log().Error(r.Context(), "ErrorHandler ", err)
|
|
|
}
|
|
|
// 代理请求
|
|
|
proxyClient.CreateCustomProxyClient(proxyAddr, errHandel).ServeHTTP(r.Response.ResponseWriter, r.Request)
|