From 010107ad2f0efda49f656da09be4b6875cb08d0b Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Wed, 5 Feb 2025 19:06:39 +0200 Subject: [PATCH] appview/keys: be a little more http --- appview/state/state.go | 11 ++++++++--- knotserver/jetstream.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/appview/state/state.go b/appview/state/state.go index d7e8e1a9..67a3b222 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -160,19 +160,24 @@ func (s *State) Keys(w http.ResponseWriter, r *http.Request) { user = strings.TrimPrefix(user, "@") if user == "" { - w.Write([]byte("not found")) + w.WriteHeader(http.StatusBadRequest) return } id, err := auth.ResolveIdent(r.Context(), user) if err != nil { - w.Write([]byte("not found")) + w.WriteHeader(http.StatusInternalServerError) return } pubKeys, err := s.db.GetPublicKeys(id.DID.String()) if err != nil { - w.Write([]byte("not found")) + w.WriteHeader(http.StatusNotFound) + return + } + + if len(pubKeys) == 0 { + w.WriteHeader(http.StatusNotFound) return } diff --git a/knotserver/jetstream.go b/knotserver/jetstream.go index d8a80297..4cd2f5ca 100644 --- a/knotserver/jetstream.go +++ b/knotserver/jetstream.go @@ -177,6 +177,11 @@ func (h *Handle) fetchAndAddKeys(ctx context.Context, did string) error { } defer resp.Body.Close() + if resp.StatusCode == http.StatusNotFound { + l.Info("no keys found for did", "did", did) + return nil + } + if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") { return fmt.Errorf("unexpected content type: %s", ct) } -- 2.54.0