Skip to content

Commit

Permalink
refactor: recover 时同时打印堆栈信息
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Mar 11, 2024
1 parent dce1c13 commit 4826cdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/issue9/query/v3 v3.1.3
github.com/issue9/scheduled v0.19.3
github.com/issue9/sliceutil v0.15.1
github.com/issue9/source v0.8.2
github.com/issue9/term/v3 v3.2.7
github.com/issue9/unique/v2 v2.0.1
github.com/klauspost/compress v1.17.7
Expand All @@ -27,7 +28,6 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/issue9/rands/v2 v2.0.1 // indirect
github.com/issue9/source v0.8.2 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
Expand Down
9 changes: 5 additions & 4 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/issue9/mux/v7"
"github.com/issue9/mux/v7/group"
"github.com/issue9/mux/v7/types"
"github.com/issue9/source"

"github.com/issue9/web/internal/errs"
"github.com/issue9/web/internal/header"
Expand Down Expand Up @@ -102,8 +103,8 @@ func Recovery(l *logs.Logger) RouterOption {
return mux.Recovery(func(w http.ResponseWriter, msg any) {
err, ok := msg.(error)
if !ok {
l.Print(msg)
w.WriteHeader(http.StatusInternalServerError)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
l.String(source.Stack(4, err))
return
}

Expand All @@ -112,8 +113,8 @@ func Recovery(l *logs.Logger) RouterOption {
he.Status = http.StatusInternalServerError
he.Message = err
}
l.Error(he.Message)
w.WriteHeader(he.Status)
http.Error(w, http.StatusText(he.Status), he.Status)
l.String(source.Stack(4, he.Message))
})
}

Expand Down
2 changes: 1 addition & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// Version 当前框架的版本
const Version = "0.87.5"
const Version = "0.87.6"

type (
Logger = logs.Logger
Expand Down

0 comments on commit 4826cdb

Please sign in to comment.