aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/alps/main.go3
-rw-r--r--plugins/base/routes.go2
-rw-r--r--renderer.go13
-rw-r--r--server.go26
-rw-r--r--themes/alps/assets/style.css13
-rw-r--r--themes/alps/error.html14
-rw-r--r--themes/alps/nav.html2
7 files changed, 59 insertions, 14 deletions
diff --git a/cmd/alps/main.go b/cmd/alps/main.go
index fc1fdd8..b013701 100644
--- a/cmd/alps/main.go
+++ b/cmd/alps/main.go
@@ -70,9 +70,6 @@ func main() {
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} method=${method}, uri=${uri}, status=${status}\n",
}))
- }
-
- if options.Debug {
e.Logger.SetLevel(log.DEBUG)
}
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 8698a3a..2107abb 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -118,7 +118,7 @@ func newIMAPBaseRenderData(ctx *alps.Context,
}
if mboxName != "" {
if active, err = getMailboxStatus(c, mboxName); err != nil {
- return err
+ return echo.NewHTTPError(http.StatusNotFound, err)
}
}
if mboxName == "INBOX" {
diff --git a/renderer.go b/renderer.go
index 4875745..1123b0b 100644
--- a/renderer.go
+++ b/renderer.go
@@ -70,14 +70,19 @@ type RenderData interface {
// BaseRenderData: *alps.NewBaseRenderData(ctx),
// // other fields...
// }
-func NewBaseRenderData(ctx *Context) *BaseRenderData {
+func NewBaseRenderData(ectx echo.Context) *BaseRenderData {
+ ctx, isactx := ectx.(*Context)
+
global := GlobalRenderData{
Extra: make(map[string]interface{}),
- Path: strings.Split(ctx.Request().URL.Path, "/")[1:],
+ Path: strings.Split(ectx.Request().URL.Path, "/")[1:],
Title: "Webmail",
- URL: ctx.Request().URL,
+ URL: ectx.Request().URL,
HavePlugin: func(name string) bool {
+ if !isactx {
+ return false
+ }
for _, plugin := range ctx.Server.plugins {
if plugin.Name() == name {
return true
@@ -87,7 +92,7 @@ func NewBaseRenderData(ctx *Context) *BaseRenderData {
},
}
- if ctx.Session != nil {
+ if isactx && ctx.Session != nil {
global.LoggedIn = true
global.Username = ctx.Session.username
}
diff --git a/server.go b/server.go
index 7159697..b1ac3a1 100644
--- a/server.go
+++ b/server.go
@@ -382,15 +382,31 @@ func New(e *echo.Echo, options *Options) (*Server, error) {
return nil, err
}
- e.HTTPErrorHandler = func(err error, c echo.Context) {
+ e.HTTPErrorHandler = func(err error, ctx echo.Context) {
code := http.StatusInternalServerError
if he, ok := err.(*echo.HTTPError); ok {
code = he.Code
- } else {
- c.Logger().Error(err)
}
- // TODO: hide internal errors
- c.String(code, err.Error())
+
+ type ErrorRenderData struct {
+ BaseRenderData
+ Code int
+ Err error
+ Status string
+ }
+ rdata := ErrorRenderData{
+ BaseRenderData: *NewBaseRenderData(ctx),
+ Err: err,
+ Code: code,
+ Status: http.StatusText(code),
+ }
+
+ if err := ctx.Render(code, "error.html", &rdata); err != nil {
+ ctx.Logger().Error(fmt.Errorf(
+ "Error occured rendering error page: %w. How meta.", err))
+ }
+
+ ctx.Logger().Error(err)
}
e.Pre(func(next echo.HandlerFunc) echo.HandlerFunc {
diff --git a/themes/alps/assets/style.css b/themes/alps/assets/style.css
index 27d8463..e07f4e2 100644
--- a/themes/alps/assets/style.css
+++ b/themes/alps/assets/style.css
@@ -123,8 +123,19 @@ footer { text-align: right; }
.actions { padding: 0.5rem; }
-.container { flex: 1 auto; display: flex; flex-direction: column; flex-wrap: nowrap; min-width: 0; }
+.container {
+ flex: 1 auto;
+ display: flex;
+ flex-direction: column;
+ flex-wrap: nowrap;
+ min-width: 0;
+}
+.container.error {
+ max-width: 800px;
+ margin: 0 auto;
+ padding: 1rem 0;
+}
aside { flex: 0 0 180px; }
diff --git a/themes/alps/error.html b/themes/alps/error.html
new file mode 100644
index 0000000..2e25f60
--- /dev/null
+++ b/themes/alps/error.html
@@ -0,0 +1,14 @@
+{{template "head.html" .}}
+
+<div class="page-wrap">
+ <div class="container error">
+ <h1>{{.Code}}: {{.Status}}</h1>
+ <p>
+ An error occured. You can try
+ <a href="/">returning to your inbox</a>,
+ or contact support.
+ </p>
+ </div>
+</div>
+
+{{template "foot.html"}}
diff --git a/themes/alps/nav.html b/themes/alps/nav.html
index d14a862..d7eee9c 100644
--- a/themes/alps/nav.html
+++ b/themes/alps/nav.html
@@ -22,10 +22,12 @@
{{ end }}
>Contacts</a>
{{ end }}
+ {{ if .GlobalData.LoggedIn }}
<div>
<span>{{ .GlobalData.Username }}</span>
<a href="/settings">Settings</a>
<a href="/logout">Sign Out</a>
</div>
+ {{ end }}
</nav>
</header>