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
f4a64502
Commit
f4a64502
authored
Apr 11, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add error show page
parent
ddc3d7d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletion
+79
-1
errors.go
errors.go
+70
-0
router.go
router.go
+9
-1
No files found.
errors.go
0 → 100644
View file @
f4a64502
package
beego
import
(
"fmt"
"html/template"
"net/http"
"runtime"
)
var
tpl
=
`
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>beego application error</title>
<style>
html, body, body * {padding: 0; margin: 0;}
#header {background:#ffd; border-bottom:solid 2px #A31515; padding: 20px 10px;}
#header h2{ }
#footer {border-top:solid 1px #aaa; padding: 5px 10px; font-size: 12px; color:green;}
#content {padding: 5px;}
#content .stack b{ font-size: 13px; color: red;}
#content .stack pre{padding-left: 10px;}
table {}
td.t {text-align: right; padding-right: 5px; color: #888;}
</style>
<script type="text/javascript">
</script>
</head>
<body>
<div id="header">
<h2>{{.AppError}}</h2>
</div>
<div id="content">
<table>
<tr>
<td class="t">Request Method: </td><td>{{.RequestMethod}}</td>
</tr>
<tr>
<td class="t">Request URL: </td><td>{{.RequestURL}}</td>
</tr>
<tr>
<td class="t">RemoteAddr: </td><td>{{.RemoteAddr }}</td>
</tr>
</table>
<div class="stack">
<b>Stack</b>
<pre>{{.Stack}}</pre>
</div>
</div>
<div id="footer">
<p>beego {{ .BeegoVersion }} (beego framework)</p>
<p>golang version: {{.GoVersion}}</p>
</div>
</body>
</html>
`
func
ShowErr
(
err
interface
{},
rw
http
.
ResponseWriter
,
r
*
http
.
Request
,
Stack
string
)
{
t
,
err
:=
template
.
New
(
"beegoerrortemp"
)
.
Parse
(
tpl
)
data
:=
make
(
map
[
string
]
string
)
data
[
"AppError"
]
=
AppName
+
":"
+
fmt
.
Sprint
(
err
)
data
[
"RequestMethod"
]
=
r
.
Method
data
[
"RequestURL"
]
=
r
.
RequestURI
data
[
"RemoteAddr"
]
=
r
.
RemoteAddr
data
[
"Stack"
]
=
Stack
data
[
"BeegoVersion"
]
=
VERSION
data
[
"GoVersion"
]
=
runtime
.
Version
()
t
.
Execute
(
rw
,
data
)
}
router.go
View file @
f4a64502
package
beego
package
beego
import
(
import
(
"fmt"
"net/http"
"net/http"
"net/url"
"net/url"
"reflect"
"reflect"
...
@@ -190,13 +191,20 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -190,13 +191,20 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
// go back to panic
// go back to panic
panic
(
err
)
panic
(
err
)
}
else
{
}
else
{
var
stack
string
Critical
(
"Handler crashed with error"
,
err
)
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
+=
1
{
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
if
!
ok
{
break
break
}
}
Critical
(
file
,
line
)
Critical
(
file
,
line
)
if
RunMode
==
"dev"
{
stack
=
stack
+
fmt
.
Sprintln
(
file
,
line
)
}
}
if
RunMode
==
"dev"
{
ShowErr
(
err
,
rw
,
r
,
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