Fix incorrect HTTP status codes for client errorsUnverified
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) | ||
| 114 | 114 | uri, cid, err := client.CreateRecord(ctx, user.DID, atproto.CollectionAnnotation, record) |
| 115 | 115 | if err != nil { |
| 116 | 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 | 118 | return |
| 119 | 119 | } |
| 120 | 120 | a.URI = uri |
| @@ -161,7 +161,7 @@ func (s *Server) handleDeleteAnnotation(w http.ResponseWriter, r *http.Request) | ||
| 161 | 161 | if ok { |
| 162 | 162 | if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil { |
| 163 | 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 | 165 | return |
| 166 | 166 | } |
| 167 | 167 | } |
| @@ -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 | return | 118 | return |
| 119 | } | 119 | } |
| 120 | a.URI = uri | 120 | 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 | return | 165 | 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) { | ||
| 286 | 286 | if ok { |
| 287 | 287 | if delErr := client.DeleteRecord(ctx, user.DID, parsed.Collection, parsed.RKey); delErr != nil { |
| 288 | 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 | 290 | return |
| 291 | 291 | } |
| 292 | 292 | } |
| @@ -307,7 +307,7 @@ func (s *Server) handleLikeArticle(w http.ResponseWriter, r *http.Request) { | ||
| 307 | 307 | uri, _, err := client.CreateRecord(ctx, user.DID, atproto.CollectionLike, likeRecord) |
| 308 | 308 | if err != nil { |
| 309 | 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 | 311 | return |
| 312 | 312 | } |
| 313 | 313 | |
| @@ -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 | return | 290 | 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 | return | 311 | 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) { | ||
| 50 | 50 | |
| 51 | 51 | did, resolveErr := atproto.ResolveHandle(r.Context(), handle) |
| 52 | 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 | 54 | return |
| 55 | 55 | } |
| 56 | 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 | 83 | did, err := atproto.ResolveHandle(r.Context(), handle) |
| 84 | 84 | if err != nil { |
| 85 | 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 | 87 | return |
| 88 | 88 | } |
| 89 | 89 | |
| @@ -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 | return | 54 | 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 | return | 87 | 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) { | ||
| 164 | 164 | uri, cid, err := client.CreateRecord(r.Context(), user.DID, atproto.CollectionSubscription, record) |
| 165 | 165 | if err != nil { |
| 166 | 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 | 168 | return |
| 169 | 169 | } |
| 170 | 170 | subURI = uri |
| @@ -221,7 +221,7 @@ func (s *Server) handleRemoveFeed(w http.ResponseWriter, r *http.Request) { | ||
| 221 | 221 | if ok { |
| 222 | 222 | if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil { |
| 223 | 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 | 225 | return |
| 226 | 226 | } |
| 227 | 227 | } |
| @@ -251,7 +251,7 @@ func (s *Server) handleClearAllSubscriptions(w http.ResponseWriter, r *http.Requ | ||
| 251 | 251 | if ok { |
| 252 | 252 | if delErr := client.DeleteRecord(r.Context(), user.DID, parsed.Collection, parsed.RKey); delErr != nil { |
| 253 | 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 | 255 | return |
| 256 | 256 | } |
| 257 | 257 | } |
| @@ -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 | return | 168 | return |
| 169 | } | 169 | } |
| 170 | subURI = uri | 170 | 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 | return | 225 | 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 | return | 255 | return |
| 256 | } | 256 | } |
| 257 | } | 257 | } |