Add not-found error handler

This commit is contained in:
2021-12-03 03:01:48 +01:00
parent d9ab404cf2
commit f0b3d34c05
3 changed files with 17 additions and 0 deletions
+2
View File
@@ -3,4 +3,6 @@ package content
// Error content data // Error content data
type Error struct { type Error struct {
_ interface{} `template:"error.go.tmpl"` _ interface{} `template:"error.go.tmpl"`
Message string
} }
+14
View File
@@ -0,0 +1,14 @@
package renderer
import (
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/content"
routing "github.com/jackwhelpton/fasthttp-routing/v2"
)
// errorNotFound renders http error-404 template
func (r *Renderer) errorNotFound(c *routing.Context) (err error) {
errorContent := content.Error{Message: "not found"}
return c.Write(errorContent)
}
+1
View File
@@ -29,6 +29,7 @@ func (r *Renderer) init() {
router := routing.New() router := routing.New()
router.Use(r.useTemplateWriter) router.Use(r.useTemplateWriter)
router.NotFound(r.errorNotFound)
r.router = router r.router = router
r.handler = router.HandleRequest r.handler = router.HandleRequest