27 Star 83 Fork 11

lunny/tango

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
recovery.go 825 Bytes
一键复制 编辑 原始数据 按行查看 历史
lunny 提交于 2015-04-28 15:42 . license & small optimization
// Copyright 2015 The Tango Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tango
import (
"fmt"
"net/http"
"runtime"
)
func Recovery(debug bool) HandlerFunc {
return func(ctx *Context) {
defer func() {
if e := recover(); e != nil {
content := fmt.Sprintf("Handler crashed with error: %v", e)
for i := 1; ; i += 1 {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
} else {
content += "\n"
}
content += fmt.Sprintf("%v %v", file, line)
}
ctx.Logger.Error(content)
if !ctx.Written() {
if !debug {
content = http.StatusText(http.StatusInternalServerError)
}
ctx.Result = InternalServerError(content)
}
}
}()
ctx.Next()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lunny/tango.git
git@gitee.com:lunny/tango.git
lunny
tango
tango
v0.5.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385