mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 00:41:10 +08:00
optimize defaulterrorhandle && add SetRespBodyFile
This commit is contained in:
parent
9ec1d1f2c6
commit
76d07364ae
2 changed files with 68 additions and 0 deletions
15
engine.go
15
engine.go
|
|
@ -121,6 +121,21 @@ func defaultErrorWarp(handler ErrorHandler) ErrorHandler {
|
|||
return
|
||||
}
|
||||
}
|
||||
// 查看context内有没有收集到error
|
||||
if len(c.Errors) > 0 {
|
||||
c.Errorf("errpage: context errors: %v, current error: %v", errors.Join(c.Errors...), err)
|
||||
if err == nil {
|
||||
err = errors.Join(c.Errors...)
|
||||
}
|
||||
}
|
||||
// 如果客户端已经断开连接,则不尝试写入响应
|
||||
// 避免在客户端已关闭连接后写入响应导致的问题
|
||||
// 检查 context.Context 是否已取消
|
||||
if errors.Is(c.Request.Context().Err(), context.Canceled) {
|
||||
log.Printf("errpage: client disconnected, skipping error page rendering for status %d, err: %v", code, err)
|
||||
return
|
||||
}
|
||||
|
||||
handler(c, code, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue