nandi/gleanpublic⑂ Fork 0
⑂ 2707cd5
Commits
⬇ Clone ▾
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Fix incorrect HTTP status codes for client errorsUnverified

Julien Robert committed 2026-04-28T23:40:27+02:00 Browse files
2707cd5 parent: decfb0a
modified internal/server/annotations_handler.go +2 -2
@@ -114,7 +114,7 @@ func (s *Server) handleCreateAnnotation(w http.ResponseWriter, r *http.Request)
114114 uri, cid, err := client.CreateRecord(ctx, user.DID, atproto.CollectionAnnotation, record)
115115 if err != nil {
116116 s.logger.Error("failed to write annotation to PDS", "error", err)
117- http.Error(w, "failed to write annotation to PDS: "+err.Error(), http.StatusBadGateway)
117+ http.Error(w, "failed to write annotation to PDS: "+err.Error(), http.StatusInternalServerError)
118118 return
119119 }
120120 a.URI = uri
@@ -161,7 +161,7 @@ func (s *Server) handleDeleteAnnotation(w http.ResponseWriter, r *http.Request)
161161 if ok {
162162 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {
163163 s.logger.Error("failed to delete annotation from PDS", "error", delErr)
164- http.Error(w, "failed to delete annotation from PDS: "+delErr.Error(), http.StatusBadGateway)
164+ http.Error(w, "failed to delete annotation from PDS: "+delErr.Error(), http.StatusInternalServerError)
165165 return
166166 }
167167 }
@@ -114,7 +114,7 @@ func (s *Server) handleCreateAnnotation(w http.ResponseWriter, r *http.Request)
114 uri, cid, err := client.CreateRecord(ctx, user.DID, atproto.CollectionAnnotation, record)114 uri, cid, err := client.CreateRecord(ctx, user.DID, atproto.CollectionAnnotation, record)
115 if err != nil {115 if err != nil {
116 s.logger.Error("failed to write annotation to PDS", "error", err)116 s.logger.Error("failed to write annotation to PDS", "error", err)
117- http.Error(w, "failed to write annotation to PDS: "+err.Error(), http.StatusBadGateway)117+ http.Error(w, "failed to write annotation to PDS: "+err.Error(), http.StatusInternalServerError)
118 return118 return
119 }119 }
120 a.URI = uri120 a.URI = uri
@@ -161,7 +161,7 @@ func (s *Server) handleDeleteAnnotation(w http.ResponseWriter, r *http.Request)
161 if ok {161 if ok {
162 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {162 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {
163 s.logger.Error("failed to delete annotation from PDS", "error", delErr)163 s.logger.Error("failed to delete annotation from PDS", "error", delErr)
164- http.Error(w, "failed to delete annotation from PDS: "+delErr.Error(), http.StatusBadGateway)164+ http.Error(w, "failed to delete annotation from PDS: "+delErr.Error(), http.StatusInternalServerError)
165 return165 return
166 }166 }
167 }167 }
modified internal/server/articles_handler.go +2 -2
@@ -286,7 +286,7 @@ func (s *Server) handleLikeArticle(w http.ResponseWriter, r *http.Request) {
286286 if ok {
287287 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {
288288 s.logger.Error("failed to delete like from PDS", "error", delErr)
289- http.Error(w, "failed to delete like from PDS: "+delErr.Error(), http.StatusBadGateway)
289+ http.Error(w, "failed to delete like from PDS: "+delErr.Error(), http.StatusInternalServerError)
290290 return
291291 }
292292 }
@@ -307,7 +307,7 @@ func (s *Server) handleLikeArticle(w http.ResponseWriter, r *http.Request) {
307307 uri, _, err := client.CreateRecord(ctx, user.DID, atproto.CollectionLike, likeRecord)
308308 if err != nil {
309309 s.logger.Error("failed to write like to PDS", "error", err)
310- http.Error(w, "failed to write like to PDS: "+err.Error(), http.StatusBadGateway)
310+ http.Error(w, "failed to write like to PDS: "+err.Error(), http.StatusInternalServerError)
311311 return
312312 }
313313
@@ -286,7 +286,7 @@ func (s *Server) handleLikeArticle(w http.ResponseWriter, r *http.Request) {
286 if ok {286 if ok {
287 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {287 if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil {
288 s.logger.Error("failed to delete like from PDS", "error", delErr)288 s.logger.Error("failed to delete like from PDS", "error", delErr)
289- http.Error(w, "failed to delete like from PDS: "+delErr.Error(), http.StatusBadGateway)289+ http.Error(w, "failed to delete like from PDS: "+delErr.Error(), http.StatusInternalServerError)
290 return290 return
291 }291 }
292 }292 }
@@ -307,7 +307,7 @@ func (s *Server) handleLikeArticle(w http.ResponseWriter, r *http.Request) {
307 uri, _, err := client.CreateRecord(ctx, user.DID, atproto.CollectionLike, likeRecord)307 uri, _, err := client.CreateRecord(ctx, user.DID, atproto.CollectionLike, likeRecord)
308 if err != nil {308 if err != nil {
309 s.logger.Error("failed to write like to PDS", "error", err)309 s.logger.Error("failed to write like to PDS", "error", err)
310- http.Error(w, "failed to write like to PDS: "+err.Error(), http.StatusBadGateway)310+ http.Error(w, "failed to write like to PDS: "+err.Error(), http.StatusInternalServerError)
311 return311 return
312 }312 }
313 313
modified internal/server/auth_handler.go +2 -2
@@ -50,7 +50,7 @@ func (s *Server) handleAuthStart(w http.ResponseWriter, r *http.Request) {
5050
5151 did, resolveErr := atproto.ResolveHandle(r.Context(), handle)
5252 if resolveErr != nil {
53- s.renderError(w, r, http.StatusBadGateway, "Handle not found", "Could not resolve that handle. Please check and try again.")
53+ s.renderError(w, r, http.StatusBadRequest, "Handle not found", "Could not resolve that handle. Please check and try again.")
5454 return
5555 }
5656 user, createErr := s.dbs.Users.CreateUser(r.Context(), did)
@@ -83,7 +83,7 @@ func (s *Server) handleAuthCallback(w http.ResponseWriter, r *http.Request) {
8383 did, err := atproto.ResolveHandle(r.Context(), handle)
8484 if err != nil {
8585 s.logger.Error("failed to resolve handle", "error", err)
86- s.renderError(w, r, http.StatusBadGateway, "Handle not found", "Could not resolve that handle. Please check and try again.")
86+ s.renderError(w, r, http.StatusBadRequest, "Handle not found", "Could not resolve that handle. Please check and try again.")
8787 return
8888 }
8989
@@ -50,7 +50,7 @@ func (s *Server) handleAuthStart(w http.ResponseWriter, r *http.Request) {
50 50
51 did, resolveErr := atproto.ResolveHandle(r.Context(), handle)51 did, resolveErr := atproto.ResolveHandle(r.Context(), handle)
52 if resolveErr != nil {52 if resolveErr != nil {
53- s.renderError(w, r, http.StatusBadGateway, "Handle not found", "Could not resolve that handle. Please check and try again.")53+ s.renderError(w, r, http.StatusBadRequest, "Handle not found", "Could not resolve that handle. Please check and try again.")
54 return54 return
55 }55 }
56 user, createErr := s.dbs.Users.CreateUser(r.Context(), did)56 user, createErr := s.dbs.Users.CreateUser(r.Context(), did)
@@ -83,7 +83,7 @@ func (s *Server) handleAuthCallback(w http.ResponseWriter, r *http.Request) {
83 did, err := atproto.ResolveHandle(r.Context(), handle)83 did, err := atproto.ResolveHandle(r.Context(), handle)
84 if err != nil {84 if err != nil {
85 s.logger.Error("failed to resolve handle", "error", err)85 s.logger.Error("failed to resolve handle", "error", err)
86- s.renderError(w, r, http.StatusBadGateway, "Handle not found", "Could not resolve that handle. Please check and try again.")86+ s.renderError(w, r, http.StatusBadRequest, "Handle not found", "Could not resolve that handle. Please check and try again.")
87 return87 return
88 }88 }
89 89
modified internal/server/feeds_handler.go +3 -3
@@ -164,7 +164,7 @@ func (s *Server) handleAddFeed(w http.ResponseWriter, r *http.Request) {
164164 uri, cid, err := client.CreateRecord(r.Context(), user.DID, atproto.CollectionSubscription, record)
165165 if err != nil {
166166 s.logger.Error("failed to write subscription to PDS", "error", err)
167- http.Error(w, "failed to write subscription to PDS: "+err.Error(), http.StatusBadGateway)
167+ http.Error(w, "failed to write subscription to PDS: "+err.Error(), http.StatusInternalServerError)
168168 return
169169 }
170170 subURI = uri
@@ -221,7 +221,7 @@ func (s *Server) handleRemoveFeed(w http.ResponseWriter, r *http.Request) {
221221 if ok {
222222 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {
223223 s.logger.Error("failed to delete subscription from PDS", "error", delErr)
224- http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusBadGateway)
224+ http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusInternalServerError)
225225 return
226226 }
227227 }
@@ -251,7 +251,7 @@ func (s *Server) handleClearAllSubscriptions(w http.ResponseWriter, r *http.Requ
251251 if ok {
252252 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {
253253 s.logger.Error("failed to delete subscription from PDS", "error", delErr, "uri", sub.URI.String)
254- http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusBadGateway)
254+ http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusInternalServerError)
255255 return
256256 }
257257 }
@@ -164,7 +164,7 @@ func (s *Server) handleAddFeed(w http.ResponseWriter, r *http.Request) {
164 uri, cid, err := client.CreateRecord(r.Context(), user.DID, atproto.CollectionSubscription, record)164 uri, cid, err := client.CreateRecord(r.Context(), user.DID, atproto.CollectionSubscription, record)
165 if err != nil {165 if err != nil {
166 s.logger.Error("failed to write subscription to PDS", "error", err)166 s.logger.Error("failed to write subscription to PDS", "error", err)
167- http.Error(w, "failed to write subscription to PDS: "+err.Error(), http.StatusBadGateway)167+ http.Error(w, "failed to write subscription to PDS: "+err.Error(), http.StatusInternalServerError)
168 return168 return
169 }169 }
170 subURI = uri170 subURI = uri
@@ -221,7 +221,7 @@ func (s *Server) handleRemoveFeed(w http.ResponseWriter, r *http.Request) {
221 if ok {221 if ok {
222 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {222 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {
223 s.logger.Error("failed to delete subscription from PDS", "error", delErr)223 s.logger.Error("failed to delete subscription from PDS", "error", delErr)
224- http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusBadGateway)224+ http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusInternalServerError)
225 return225 return
226 }226 }
227 }227 }
@@ -251,7 +251,7 @@ func (s *Server) handleClearAllSubscriptions(w http.ResponseWriter, r *http.Requ
251 if ok {251 if ok {
252 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {252 if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil {
253 s.logger.Error("failed to delete subscription from PDS", "error", delErr, "uri", sub.URI.String)253 s.logger.Error("failed to delete subscription from PDS", "error", delErr, "uri", sub.URI.String)
254- http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusBadGateway)254+ http.Error(w, "failed to delete subscription from PDS: "+delErr.Error(), http.StatusInternalServerError)
255 return255 return
256 }256 }
257 }257 }