Example #1
0
// errHandler renders an error using error templates if available
func errHandler(context router.Context, e error) {

	// Cast the error to a status error if it is one, if not wrap it in a Status 500 error
	err := router.ToStatusError(e)

	view := view.New(context)

	view.AddKey("title", err.Title)
	view.AddKey("message", err.Message)

	if !context.Production() {
		view.AddKey("status", err.Status)
		view.AddKey("file", err.FileLine())
		view.AddKey("error", err.Err)
	}

	// Set the status correctly for errors
	context.Writer().WriteHeader(err.Status)

	// Use our error template
	view.Template("app/views/error.html.got")

	context.Logf("#error %s\n", err)
	view.Render()
}
Example #2
0
// errHandler renders an error using error templates if available
func errHandler(context router.Context, e error) {

	// Cast the error to a status error if it is one, if not wrap it in a Status 500 error
	err := router.ToStatusError(e)

	view := view.New(context)

	view.AddKey("title", err.Title)
	view.AddKey("message", err.Message)

	if !context.Production() {
		view.AddKey("status", err.Status)
		view.AddKey("file", err.FileLine())
		view.AddKey("error", err.Err)
	}

	view.Template("app/views/error.html.got")

	// Log 404 as info only
	if err.Status == 404 {
		context.Logf("#info %s\n", err)
	} else {
		context.Logf("#error %s\n", err)
	}

	view.Render()
}