Skip to content

Commit

Permalink
chore: better error handling when portal is not responding
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarfors committed Mar 4, 2024
1 parent 6834eab commit 2cebe25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/gateway/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ func (h *AccountsHandler) servePortal(
subject: fmt.Sprintf(hz.SubjectPortalRender, portal),
account: account,
}
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
w.WriteHeader(http.StatusOK)
_ = portalError(err).Render(r.Context(), w)
}
proxy.ServeHTTP(w, r)
return
}
body := accountLayout(
account,
h.Portals,
actorProxyPage(account, portal, subpath),
portalProxy(account, portal, subpath),
)
layout(portal, &userInfo, body).Render(r.Context(), w)
}
9 changes: 8 additions & 1 deletion pkg/gateway/main.templ
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ templ accountsNewPage() {
</div>
}

templ actorProxyPage(account string, actor string, subpath string) {
templ portalProxy(account string, actor string, subpath string) {
if subpath == "" {
<div hx-get={ fmt.Sprintf("/accounts/%s/%s", account, actor) } hx-headers='{"HZ-Portal-Load-Request": "true"}' hx-trigger="load" hx-swap="outerHTML"><span class="loading loading-infinity loading-lg"></span></div>
} else {
Expand All @@ -130,3 +130,10 @@ templ loggedOutPage() {
<p>You have been logged out.</p>
</div>
}

templ portalError(err error) {
<div class="max-w-none prose md:prose-lg lg:prose-xl xl:prose-2xl">
<h1>Error</h1>
<pre>{ err.Error() }</pre>
</div>
}

0 comments on commit 2cebe25

Please sign in to comment.