Skip to content

Commit ecfb1ac

Browse files
Crash--claude
andcommitted
fix(settings): degrade gracefully when the legal notice fetch fails
GET /settings/instance fetched the optional legal_notice_url from the cloudery and propagated any error, turning the whole response into an HTTP 500 whenever the cloudery was down or slow. Since the front-end relies on this core route on nearly every page, it would then loop retrying it. The legal notice is a non-essential enrichment: log the error and omit the field instead of failing the response, so the route keeps returning the locally-available settings even when the cloudery is unreachable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent af38aca commit ecfb1ac

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

web/settings/instance.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ func (h *HTTPHandler) getInstance(c echo.Context) error {
8282
return err
8383
}
8484

85-
url, err := h.svc.GetLegalNoticeUrl(inst)
86-
if err != nil {
87-
return err
88-
}
89-
if url != "" {
85+
if url, err := h.svc.GetLegalNoticeUrl(inst); err != nil {
86+
inst.Logger().WithNamespace("settings").
87+
Warnf("Failed to fetch the legal notice URL from the cloudery: %s", err)
88+
} else if url != "" {
9089
doc.M["legal_notice_url"] = url
9190
}
9291

web/settings/settings_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,22 @@ func TestSettings(t *testing.T) {
637637
attrs.HasValue("org_id", "test-org-id-456")
638638
})
639639

640+
t.Run("GetInstanceDegradesWhenLegalNoticeFails", func(t *testing.T) {
641+
e := testutils.CreateTestClient(t, tsURL)
642+
svc.On("GetLegalNoticeUrl", testInstance).
643+
Return("", fmt.Errorf("cloudery is down")).Once()
644+
645+
obj := e.GET("/settings/instance").
646+
WithCookie(sessCookie, "connected").
647+
WithHeader("Authorization", "Bearer "+token).
648+
Expect().Status(200).
649+
JSON(httpexpect.ContentOpts{MediaType: "application/vnd.api+json"}).
650+
Object()
651+
652+
attrs := obj.Value("data").Object().Value("attributes").Object()
653+
attrs.NotContainsKey("legal_notice_url")
654+
})
655+
640656
t.Run("UpdateInstance", func(t *testing.T) {
641657
e := testutils.CreateTestClient(t, tsURL)
642658

0 commit comments

Comments
 (0)