Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (31 sloc) 0.671 kB
package mango
import (
"bytes"
"template"
)
func ShowErrors(templateString string) Middleware {
if templateString == "" {
templateString = `
<html>
<body>
<p>
{Error|html}
</p>
</body>
</html>
`
}
errorTemplate := template.MustParse(templateString, nil)
return func(env Env, app App) (status Status, headers Headers, body Body) {
defer func() {
if err := recover(); err != nil {
buffer := bytes.NewBufferString("")
errorTemplate.Execute(buffer, struct{ Error string }{err.(string)})
status = 500
headers = Headers{}
body = Body(buffer.String())
}
}()
return app(env)
}
}
Jump to Line
Something went wrong with that request. Please try again.