Skip to content

Commit

Permalink
Merge pull request #3 from dannykopping/fix-2
Browse files Browse the repository at this point in the history
Loads templates from embedded FS & improves Web UI errors
  • Loading branch information
Danny Kopping committed Jul 5, 2022
2 parents 8c292d9 + 185e012 commit 39fda0b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
16 changes: 14 additions & 2 deletions serve.go
Expand Up @@ -3,6 +3,7 @@ package errata
import (
"bytes"
"embed"
"errors"
"fmt"
"io/fs"
"net/http"
Expand Down Expand Up @@ -130,8 +131,19 @@ func (s *Server) render(w http.ResponseWriter, path string, data pongo2.Context)
s.errorHandler(w, NewFileNotReadableErr(err, path))
}

tmpl, err := pongo2.FromBytes(b)
set := pongo2.NewSet("web", pongo2.NewFSLoader(web))

tmpl, err := set.FromBytes(b)
if err != nil {
// pongo2 needs errata!
if err, ok := err.(*pongo2.Error); ok {
var pathErr *fs.PathError
if err.OrigError.Error() == "unable to resolve template" || errors.As(err.OrigError, &pathErr) {
s.errorHandler(w, NewTemplateExecutionErr(err))
return
}
}

s.errorHandler(w, NewInvalidSyntaxErr(err, path))
return
}
Expand Down Expand Up @@ -195,7 +207,7 @@ func (s *Server) errorHandler(w http.ResponseWriter, err error) {
}
}

http.Error(w, err.Error(), statusCode)
http.Error(w, fmt.Sprintf("%+v", err), statusCode)
}

type HTTPStatusCodeExtractor interface {
Expand Down
4 changes: 2 additions & 2 deletions web/list.gohtml
@@ -1,6 +1,6 @@
{% import "web/item.gohtml" erratum %}
{% import "web/sidebar.gohtml" sidebar %}
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
{{ sidebar(Errors) }}
Expand All @@ -21,4 +21,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}
4 changes: 2 additions & 2 deletions web/search-miss.gohtml
@@ -1,4 +1,4 @@
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
<div class="docs-content">
Expand All @@ -10,4 +10,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}
4 changes: 2 additions & 2 deletions web/single.gohtml
@@ -1,5 +1,5 @@
{% import "web/item.gohtml" erratum %}
{% ssi "web/header.gohtml" %}
{% ssi "web/header.gohtml" parsed %}

<div class="docs-wrapper">
<div class="docs-content">
Expand All @@ -11,4 +11,4 @@
</div>
</div><!--//docs-wrapper-->

{% ssi "web/footer.gohtml" %}
{% ssi "web/footer.gohtml" parsed %}

0 comments on commit 39fda0b

Please sign in to comment.