Skip to content

Commit

Permalink
AboutErr 404 page for invalid files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Oct 30, 2023
1 parent 00801e2 commit 100d0f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 0 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ The following options can be added to [Override].
# Bugs
- `public/text/osd.xml` needs updating to use current search links.
- /f/{{bad id}} currently returns a 500 error, should return a 404.
- also check groups for the same problem.
- ren x_pression to x_pression-design
Expand Down
5 changes: 4 additions & 1 deletion handler/app/render_about.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (a AboutConf) About(z *zap.SugaredLogger, c echo.Context) error {
}
res, err := model.OneRecord(z, c, a.URI)
if err != nil {
return DatabaseErr(z, c, "f/"+a.URI, ErrZap)
if errors.Is(err, model.ErrID) {
return AboutErr(z, c, a.URI)
}
return DatabaseErr(z, c, "f/"+a.URI, err)
}
fname := res.Filename.String
uuid := res.UUID.String
Expand Down
27 changes: 26 additions & 1 deletion handler/app/render_err.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,38 @@ import (
"go.uber.org/zap"
)

// AboutErr renders the about file error page for the the About files links.
func AboutErr(z *zap.SugaredLogger, c echo.Context, id string) error {
const name = "status"
if z == nil {
return InternalErr(z, c, name, ErrZap)
}
if c == nil {
return InternalErr(z, c, name, ErrCxt)
}
data := empty()
data["title"] = fmt.Sprintf("%d error, file about page not found", http.StatusNotFound)
data["description"] = fmt.Sprintf("HTTP status %d error", http.StatusNotFound)
data["code"] = http.StatusNotFound
data["logo"] = "About file not found"
data["alert"] = fmt.Sprintf("About file %q cannot be found", strings.ToLower(id))
data["probl"] = "The about file page does not exist, there is probably a typo with the URL."
data["uriOkay"] = "f/"
data["uriErr"] = id
err := c.Render(http.StatusNotFound, name, data)
if err != nil {
return InternalErr(z, c, name, err)
}
return nil
}

// DatabaseErr is the handler for handling database connection errors.
func DatabaseErr(z *zap.SugaredLogger, c echo.Context, uri string, err error) error {
const code = http.StatusInternalServerError
if z == nil {
zapNil(err)
} else if err != nil {
z.Warnf("%d error for %q: %s", code, uri, err)
z.Errorf("%d error for %q: %s", code, uri, err)
}
// render the fallback, text only error page
if c == nil {
Expand Down

0 comments on commit 100d0f0

Please sign in to comment.