diff --git a/beacon-chain/rpc/eth/rewards/handlers.go b/beacon-chain/rpc/eth/rewards/handlers.go index 87be7a5a60..9174feb1b6 100644 --- a/beacon-chain/rpc/eth/rewards/handlers.go +++ b/beacon-chain/rpc/eth/rewards/handlers.go @@ -228,7 +228,7 @@ func (s *Server) attRewardsState(w http.ResponseWriter, r *http.Request) (state. } st, err := s.Stater.StateBySlot(r.Context(), nextEpochEnd) if err != nil { - httputil.HandleError(w, "Could not get state for epoch's starting slot: "+err.Error(), http.StatusInternalServerError) + shared.WriteStateFetchError(w, err) return nil, false } return st, true diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index a382c7d386..11f0488a02 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -911,7 +911,7 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) { st, err := s.Stater.StateBySlot(ctx, startSlot) if err != nil { - httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError) + shared.WriteStateFetchError(w, err) return } @@ -1030,7 +1030,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) { if requestedEpoch < currentEpoch { st, err = s.Stater.StateBySlot(ctx, epochStartSlot) if err != nil { - httputil.HandleError(w, fmt.Sprintf("Could not get state for slot %d: %v ", epochStartSlot, err), http.StatusInternalServerError) + shared.WriteStateFetchError(w, err) return } } else { @@ -1181,7 +1181,7 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request) } st, err := s.Stater.State(ctx, []byte(strconv.FormatUint(uint64(slot), 10))) if err != nil { - httputil.HandleError(w, "Could not get sync committee state: "+err.Error(), http.StatusInternalServerError) + shared.WriteStateFetchError(w, err) return } @@ -1327,7 +1327,7 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) { } st, err = s.Stater.StateBySlot(ctx, epochEnd) if err != nil { - httputil.HandleError(w, "Could not get slot for requested epoch: "+err.Error(), http.StatusInternalServerError) + shared.WriteStateFetchError(w, err) return } participation, err = st.CurrentEpochParticipation() diff --git a/changelog/radek_use-statefetch-error.md b/changelog/radek_use-statefetch-error.md new file mode 100644 index 0000000000..dcf01c910d --- /dev/null +++ b/changelog/radek_use-statefetch-error.md @@ -0,0 +1,3 @@ +### Ignored + +- Use `WriteStateFetchError` in API handlers whenever possible. \ No newline at end of file