Skip to content

Commit

Permalink
webapi: Attempt cache updat before returning error
Browse files Browse the repository at this point in the history
Rather than immediately returning an error if the cache is not
initialized, attempt to initialize it first.
  • Loading branch information
jholdstock committed Sep 18, 2023
1 parent 3e75384 commit 69e2c32
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/webapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ func (w *WebAPI) withSession(store *sessions.CookieStore) gin.HandlerFunc {
// Server Error.
func (w *WebAPI) requireWebCache(c *gin.Context) {
if !w.cache.initialized() {
const str = "Cache is not yet initialized"
w.log.Errorf(str)
c.String(http.StatusInternalServerError, str)
c.Abort()
return
// Try to initialize it now.
err := w.cache.update()
if err != nil {
w.log.Errorf("Failed to initialize cache: %v", err)
c.String(http.StatusInternalServerError, "Cache is not initialized")
c.Abort()
return
}
}

c.Set(cacheKey, w.cache.getData())
Expand Down

0 comments on commit 69e2c32

Please sign in to comment.