Combine error templates.
This commit is contained in:
parent
3a9f0d1879
commit
58e75cf7a6
8 changed files with 24 additions and 18 deletions
1
Makefile
1
Makefile
|
|
@ -21,4 +21,5 @@ up:
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run:
|
run:
|
||||||
|
clear
|
||||||
go run main.go
|
go run main.go
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
@ -26,8 +25,7 @@ func (e *Error) Get(err error, c echo.Context) {
|
||||||
p := NewPage(c)
|
p := NewPage(c)
|
||||||
p.Layout = "main"
|
p.Layout = "main"
|
||||||
p.Title = http.StatusText(code)
|
p.Title = http.StatusText(code)
|
||||||
// TODO: fallback if there is no error template
|
p.Name = "error"
|
||||||
p.Name = fmt.Sprintf("errors/%d", code)
|
|
||||||
p.StatusCode = code
|
p.StatusCode = code
|
||||||
|
|
||||||
if err = e.RenderPage(c, p); err != nil {
|
if err = e.RenderPage(c, p); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ type Page struct {
|
||||||
MaxAge time.Duration
|
MaxAge time.Duration
|
||||||
Tags []string
|
Tags []string
|
||||||
}
|
}
|
||||||
|
RequestID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPage(c echo.Context) Page {
|
func NewPage(c echo.Context) Page {
|
||||||
|
|
@ -51,6 +52,7 @@ func NewPage(c echo.Context) Page {
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Pager: pager.NewPager(c, DefaultItemsPerPage),
|
Pager: pager.NewPager(c, DefaultItemsPerPage),
|
||||||
Headers: make(map[string]string),
|
Headers: make(map[string]string),
|
||||||
|
RequestID: c.Response().Header().Get(echo.HeaderXRequestID),
|
||||||
}
|
}
|
||||||
|
|
||||||
p.IsHome = p.Path == "/"
|
p.IsHome = p.Path == "/"
|
||||||
|
|
|
||||||
11
views/pages/error.gohtml
Normal file
11
views/pages/error.gohtml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{{define "content"}}
|
||||||
|
{{if gt .StatusCode 500}}
|
||||||
|
<p>Please try again. Request ID: {{.RequestID}}</p>
|
||||||
|
{{else if or (eq .StatusCode 403) (eq .StatusCode 401)}}
|
||||||
|
<p>You are not authorized to view the requested page.</p>
|
||||||
|
{{else if eq .StatusCode 404}}
|
||||||
|
<p>Click {{link (call .Reverse "home") "here" .Path}} to return home</p>
|
||||||
|
{{else}}
|
||||||
|
<p>Something went wrong</p>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{{define "content"}}
|
|
||||||
<p>Click {{link (call .Reverse "home") "here" .Path}} to return home</p>
|
|
||||||
{{end}}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{{define "content"}}
|
|
||||||
<p>Please try again</p>
|
|
||||||
{{end}}
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="" class="label">Username</label>
|
<label for="username" class="label">Username</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input type="textfield" name="username" class="input" value="{{.Data.Username}}" required>
|
<input type="text" id="username" name="username" class="input" value="{{.Data.Username}}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="" class="label">Password</label>
|
<label for="password" class="label">Password</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input type="password" name="password" placeholder="*******" class="input" required>
|
<input type="password" id="password" name="password" placeholder="*******" class="input" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue