Add not-found error handler

pull/1/head
Nikita Tokarchuk 3 years ago
parent d9ab404cf2
commit f0b3d34c05
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 2
      frontend/content/error.go
  2. 14
      frontend/renderer/error.go
  3. 1
      frontend/renderer/renderer.go

@ -3,4 +3,6 @@ package content
// Error content data
type Error struct {
_ interface{} `template:"error.go.tmpl"`
Message string
}

@ -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)
}

@ -29,6 +29,7 @@ func (r *Renderer) init() {
router := routing.New()
router.Use(r.useTemplateWriter)
router.NotFound(r.errorNotFound)
r.router = router
r.handler = router.HandleRequest

Loading…
Cancel
Save