Use CreateAPIErrReader for error_page middleware

This commit is contained in:
joncrangle
2023-12-14 21:50:48 -05:00
parent b8fb930987
commit e8255bd3a7
5 changed files with 49 additions and 15 deletions

View File

@@ -390,18 +390,18 @@ func (chain *ProxyChain) SetDebugLogging(isDebugMode bool) *ProxyChain {
// this will prevent Execute from firing and reset the state
// returns the initial error enriched with context
func (chain *ProxyChain) abort(err error) error {
// defer chain._reset()
defer chain._reset()
chain.abortErr = err
chain.Context.Response().SetStatusCode(500)
var e error
if chain.Request.URL != nil {
e = fmt.Errorf("ProxyChain error for '%s': %s", chain.Request.URL.String(), err.Error())
} else {
e = fmt.Errorf("ProxyChain error: '%s'", err.Error())
}
// chain.Context.Response().SetStatusCode(500)
// var e error
// if chain.Request.URL != nil {
// e = fmt.Errorf("ProxyChain error for '%s': %s", chain.Request.URL.String(), err.Error())
// } else {
// e = fmt.Errorf("ProxyChain error: '%s'", err.Error())
// }
// chain.Context.SendString(e.Error()) // <- RenderErrorPage middleware to render error
log.Println(e.Error())
return e
// log.Println(e.Error())
return err
}
// internal function to reset state of ProxyChain for reuse