Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
421bf97b
Commit
421bf97b
authored
Sep 15, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support custome recover func fix #2004
parent
c1650760
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
32 deletions
+38
-32
config.go
config.go
+35
-0
router.go
router.go
+3
-32
No files found.
config.go
View file @
421bf97b
...
...
@@ -19,9 +19,11 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/session"
"github.com/astaxie/beego/utils"
...
...
@@ -34,6 +36,7 @@ type Config struct {
RouterCaseSensitive
bool
ServerName
string
RecoverPanic
bool
RecoverFunc
func
(
*
context
.
Context
)
CopyRequestBody
bool
EnableGzip
bool
MaxMemory
int64
...
...
@@ -142,6 +145,37 @@ func init() {
}
}
func
recoverPanic
(
ctx
*
context
.
Context
)
{
if
err
:=
recover
();
err
!=
nil
{
if
err
==
ErrAbort
{
return
}
if
!
BConfig
.
RecoverPanic
{
panic
(
err
)
}
if
BConfig
.
EnableErrorsShow
{
if
_
,
ok
:=
ErrorMaps
[
fmt
.
Sprint
(
err
)];
ok
{
exception
(
fmt
.
Sprint
(
err
),
ctx
)
return
}
}
var
stack
string
logs
.
Critical
(
"the request url is "
,
ctx
.
Input
.
URL
())
logs
.
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
break
}
logs
.
Critical
(
fmt
.
Sprintf
(
"%s:%d"
,
file
,
line
))
stack
=
stack
+
fmt
.
Sprintln
(
fmt
.
Sprintf
(
"%s:%d"
,
file
,
line
))
}
if
BConfig
.
RunMode
==
DEV
{
showErr
(
err
,
ctx
,
stack
)
}
}
}
func
newBConfig
()
*
Config
{
return
&
Config
{
AppName
:
"beego"
,
...
...
@@ -149,6 +183,7 @@ func newBConfig() *Config {
RouterCaseSensitive
:
true
,
ServerName
:
"beegoServer:"
+
VERSION
,
RecoverPanic
:
true
,
RecoverFunc
:
recoverPanic
,
CopyRequestBody
:
false
,
EnableGzip
:
false
,
MaxMemory
:
1
<<
26
,
//64MB
...
...
router.go
View file @
421bf97b
...
...
@@ -626,7 +626,9 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context
.
Reset
(
rw
,
r
)
defer
p
.
pool
.
Put
(
context
)
defer
p
.
recoverPanic
(
context
)
if
BConfig
.
RecoverFunc
!=
nil
{
defer
BConfig
.
RecoverFunc
(
context
)
}
context
.
Output
.
EnableGzip
=
BConfig
.
EnableGzip
...
...
@@ -878,37 +880,6 @@ func (p *ControllerRegister) FindRouter(context *beecontext.Context) (routerInfo
return
}
func
(
p
*
ControllerRegister
)
recoverPanic
(
context
*
beecontext
.
Context
)
{
if
err
:=
recover
();
err
!=
nil
{
if
err
==
ErrAbort
{
return
}
if
!
BConfig
.
RecoverPanic
{
panic
(
err
)
}
if
BConfig
.
EnableErrorsShow
{
if
_
,
ok
:=
ErrorMaps
[
fmt
.
Sprint
(
err
)];
ok
{
exception
(
fmt
.
Sprint
(
err
),
context
)
return
}
}
var
stack
string
logs
.
Critical
(
"the request url is "
,
context
.
Input
.
URL
())
logs
.
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
break
}
logs
.
Critical
(
fmt
.
Sprintf
(
"%s:%d"
,
file
,
line
))
stack
=
stack
+
fmt
.
Sprintln
(
fmt
.
Sprintf
(
"%s:%d"
,
file
,
line
))
}
if
BConfig
.
RunMode
==
DEV
{
showErr
(
err
,
context
,
stack
)
}
}
}
func
toURL
(
params
map
[
string
]
string
)
string
{
if
len
(
params
)
==
0
{
return
""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment