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
0859ec57
Commit
0859ec57
authored
Mar 17, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor of error response and fix err code bug
parent
443d7139
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
21 deletions
+24
-21
controller.go
controller.go
+2
-1
error.go
error.go
+4
-1
router.go
router.go
+18
-19
No files found.
controller.go
View file @
0859ec57
...
@@ -261,12 +261,13 @@ func (c *Controller) Abort(code string) {
...
@@ -261,12 +261,13 @@ func (c *Controller) Abort(code string) {
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
func
(
c
*
Controller
)
CustomAbort
(
status
int
,
body
string
)
{
func
(
c
*
Controller
)
CustomAbort
(
status
int
,
body
string
)
{
c
.
Ctx
.
Output
.
Status
=
status
// first panic from ErrorMaps, is is user defined error functions.
// first panic from ErrorMaps, is is user defined error functions.
if
_
,
ok
:=
ErrorMaps
[
body
];
ok
{
if
_
,
ok
:=
ErrorMaps
[
body
];
ok
{
c
.
Ctx
.
Output
.
Status
=
status
panic
(
body
)
panic
(
body
)
}
}
// last panic user string
// last panic user string
c
.
Ctx
.
ResponseWriter
.
WriteHeader
(
status
)
c
.
Ctx
.
ResponseWriter
.
Write
([]
byte
(
body
))
c
.
Ctx
.
ResponseWriter
.
Write
([]
byte
(
body
))
panic
(
ErrAbort
)
panic
(
ErrAbort
)
}
}
...
...
error.go
View file @
0859ec57
...
@@ -388,7 +388,10 @@ func exception(errCode string, ctx *context.Context) {
...
@@ -388,7 +388,10 @@ func exception(errCode string, ctx *context.Context) {
if
err
==
nil
{
if
err
==
nil
{
return
v
return
v
}
}
return
503
if
ctx
.
Output
.
Status
==
0
{
return
503
}
return
ctx
.
Output
.
Status
}
}
for
_
,
ec
:=
range
[]
string
{
errCode
,
"503"
,
"500"
}
{
for
_
,
ec
:=
range
[]
string
{
errCode
,
"503"
,
"500"
}
{
...
...
router.go
View file @
0859ec57
...
@@ -844,27 +844,26 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
...
@@ -844,27 +844,26 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
}
}
if
!
BConfig
.
RecoverPanic
{
if
!
BConfig
.
RecoverPanic
{
panic
(
err
)
panic
(
err
)
}
else
{
}
if
BConfig
.
EnableErrorsShow
{
if
BConfig
.
EnableErrorsShow
{
if
_
,
ok
:=
ErrorMaps
[
fmt
.
Sprint
(
err
)];
ok
{
if
_
,
ok
:=
ErrorMaps
[
fmt
.
Sprint
(
err
)];
ok
{
exception
(
fmt
.
Sprint
(
err
),
context
)
exception
(
fmt
.
Sprint
(
err
),
context
)
return
return
}
}
var
stack
string
Critical
(
"the request url is "
,
context
.
Input
.
URL
())
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
break
}
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
)
var
stack
string
Critical
(
"the request url is "
,
context
.
Input
.
URL
())
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
break
}
}
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
)
}
}
}
}
}
}
...
...
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