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
55f638ac
Commit
55f638ac
authored
Dec 16, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #377 from vadimi/master
Panic template execution errors to show error pages accordingly
parents
505fca93
31f862c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
controller.go
controller.go
+3
-0
router.go
router.go
+23
-8
No files found.
controller.go
View file @
55f638ac
...
...
@@ -138,6 +138,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
:=
BeeTemplates
[
c
.
TplNames
]
.
ExecuteTemplate
(
newbytes
,
c
.
TplNames
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
...
...
@@ -145,6 +146,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
=
BeeTemplates
[
c
.
Layout
]
.
ExecuteTemplate
(
ibytes
,
c
.
Layout
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
...
...
@@ -163,6 +165,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
:=
BeeTemplates
[
c
.
TplNames
]
.
ExecuteTemplate
(
ibytes
,
c
.
TplNames
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
...
...
router.go
View file @
55f638ac
...
...
@@ -26,7 +26,10 @@ const (
FinishRouter
)
var
HTTPMETHOD
=
[]
string
{
"get"
,
"post"
,
"put"
,
"delete"
,
"patch"
,
"options"
,
"head"
}
var
(
HTTPMETHOD
=
[]
string
{
"get"
,
"post"
,
"put"
,
"delete"
,
"patch"
,
"options"
,
"head"
}
errorType
=
reflect
.
TypeOf
((
*
error
)(
nil
))
.
Elem
()
)
type
controllerInfo
struct
{
pattern
string
...
...
@@ -441,7 +444,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
return
false
return
false
}
if
context
.
Input
.
IsWebsocket
()
{
...
...
@@ -481,7 +484,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
middleware
.
Exception
(
"403"
,
rw
,
r
,
"403 Forbidden"
)
goto
Admin
}
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
isStaticFileToCompress
:=
false
if
StaticExtensionsToGzip
!=
nil
&&
len
(
StaticExtensionsToGzip
)
>
0
{
...
...
@@ -513,7 +516,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
else
{
http
.
ServeFile
(
w
,
r
,
file
)
}
w
.
started
=
true
goto
Admin
}
...
...
@@ -729,7 +732,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
!
w
.
started
&&
!
context
.
Input
.
IsWebsocket
()
{
if
AutoRender
{
method
=
vc
.
MethodByName
(
"Render"
)
method
.
Call
(
in
)
callMethodWithError
(
method
,
in
)
}
}
}
...
...
@@ -885,9 +888,9 @@ func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.Resp
//responseWriter is a wrapper for the http.ResponseWriter
//started set to true if response was written to then don't execute other handler
type
responseWriter
struct
{
writer
http
.
ResponseWriter
started
bool
status
int
writer
http
.
ResponseWriter
started
bool
status
int
contentEncoding
string
}
...
...
@@ -920,3 +923,15 @@ func (w *responseWriter) WriteHeader(code int) {
w
.
started
=
true
w
.
writer
.
WriteHeader
(
code
)
}
// call method and panic with error if error is in result params
func
callMethodWithError
(
method
reflect
.
Value
,
params
[]
reflect
.
Value
)
{
results
:=
method
.
Call
(
params
)
if
len
(
results
)
>
0
{
for
_
,
result
:=
range
results
{
if
result
.
Type
()
==
errorType
&&
!
result
.
IsNil
()
{
panic
(
result
.
Interface
()
.
(
error
))
}
}
}
}
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