Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f4a64502
authored
2013-04-11 14:35:43 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add error show page
1 parent
ddc3d7d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletions
errors.go
router.go
errors.go
0 → 100644
View file @
f4a6450
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 @
f4a6450
package
beego
import
(
"fmt"
"net/http"
"net/url"
"reflect"
...
...
@@ -190,13 +191,20 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
// go back to panic
panic
(
err
)
}
else
{
var
stack
string
Critical
(
"Handler crashed with error"
,
err
)
for
i
:=
1
;
;
i
+=
1
{
for
i
:=
1
;
;
i
++
{
_
,
file
,
line
,
ok
:=
runtime
.
Caller
(
i
)
if
!
ok
{
break
}
Critical
(
file
,
line
)
if
RunMode
==
"dev"
{
stack
=
stack
+
fmt
.
Sprintln
(
file
,
line
)
}
}
if
RunMode
==
"dev"
{
ShowErr
(
err
,
rw
,
r
,
stack
)
}
}
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment