diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 51729652a9..0605bc31ba 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -648,14 +648,14 @@ func DashboardDataWithdrawals(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - utils.LogError(err, fmt.Errorf("error converting datatables data parameter from string to int: %v", err), 0) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("dashboard withdrawals data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - utils.LogError(err, fmt.Errorf("error converting datatables data parameter from string to int: %v", err), 0) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("dashboard withdrawals data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } diff --git a/handlers/epochs.go b/handlers/epochs.go index 9e2a10c32f..63a18f7a35 100644 --- a/handlers/epochs.go +++ b/handlers/epochs.go @@ -42,20 +42,20 @@ func EpochsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("epochs data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("epochs data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("epochs data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/eth1Blocks.go b/handlers/eth1Blocks.go index 363d3c79bd..5f4df32d88 100644 --- a/handlers/eth1Blocks.go +++ b/handlers/eth1Blocks.go @@ -42,20 +42,20 @@ func Eth1BlocksData(w http.ResponseWriter, r *http.Request) { } draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int for route %v: %v", r.URL.String(), err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 blocks data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int for route %v: %v", r.URL.String(), err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 blocks data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int for route %v: %v", r.URL.String(), err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 blocks data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/eth1Deposits.go b/handlers/eth1Deposits.go index a4ee7196cf..e27a6a0561 100644 --- a/handlers/eth1Deposits.go +++ b/handlers/eth1Deposits.go @@ -59,20 +59,20 @@ func Eth1DepositsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -171,20 +171,20 @@ func Eth1DepositsLeaderboardData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits leaderboard data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits leaderboard data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth1 deposits leaderboard data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/eth2Deposits.go b/handlers/eth2Deposits.go index ae3883da90..2a5dcfb090 100644 --- a/handlers/eth2Deposits.go +++ b/handlers/eth2Deposits.go @@ -27,20 +27,20 @@ func Eth2DepositsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/pools_rocketpool.go b/handlers/pools_rocketpool.go index dc174e96d5..cdf0b69e3b 100644 --- a/handlers/pools_rocketpool.go +++ b/handlers/pools_rocketpool.go @@ -32,20 +32,20 @@ func PoolsRocketpoolDataMinipools(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool minipools data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool minipools data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool minipools data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -188,20 +188,20 @@ func PoolsRocketpoolDataNodes(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool nodes data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool nodes data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool nodes data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -332,20 +332,20 @@ func PoolsRocketpoolDataDAOProposals(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao proposals data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao proposals data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao proposals data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -545,20 +545,20 @@ func PoolsRocketpoolDataDAOMembers(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao members data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao members data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("rocketpool dao members data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/slot.go b/handlers/slot.go index f2a436f8f1..f5f9527882 100644 --- a/handlers/slot.go +++ b/handlers/slot.go @@ -452,21 +452,21 @@ func SlotDepositData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 deposits data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } @@ -582,21 +582,21 @@ func SlotVoteData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 votes data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 votes data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("eth2 votes data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } diff --git a/handlers/slots.go b/handlers/slots.go index 070cfb1ab3..b404b0a36d 100644 --- a/handlers/slots.go +++ b/handlers/slots.go @@ -47,20 +47,20 @@ func SlotsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("slots data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("slots data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("slots data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } diff --git a/handlers/user.go b/handlers/user.go index fe371b2603..b094f47447 100644 --- a/handlers/user.go +++ b/handlers/user.go @@ -907,25 +907,10 @@ func UserNotificationsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("user notifications data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } - // start, err := strconv.ParseUint(q.Get("start"), 10, 64) - // if err != nil { - // logger.Errorf("error converting datatables start parameter from string to int: %v", err) - // http.Error(w, "Internal server error", http.StatusServiceUnavailable) - // return - // } - // length, err := strconv.ParseUint(q.Get("length"), 10, 64) - // if err != nil { - // logger.Errorf("error converting datatables length parameter from string to int: %v", err) - // http.Error(w, "Internal server error", http.StatusServiceUnavailable) - // return - // } - // if length > 100 { - // length = 100 - // } user := getUser(r) @@ -1020,20 +1005,14 @@ func UserSubscriptionsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("user subscriptions data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } - // start, err := strconv.ParseUint(q.Get("start"), 10, 64) - // if err != nil { - // logger.Errorf("error converting datatables start parameter from string to int: %v", err) - // http.Error(w, "Internal server error", http.StatusServiceUnavailable) - // return - // } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("user subscriptions data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/validator.go b/handlers/validator.go index 967dcc9358..055884b16e 100644 --- a/handlers/validator.go +++ b/handlers/validator.go @@ -929,20 +929,20 @@ func ValidatorProposedBlocks(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator proposed blocks data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator proposed blocks data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator proposed blocks data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -1041,8 +1041,8 @@ func ValidatorAttestations(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) index, err := strconv.ParseUint(vars["index"], 10, 64) if err != nil { - logger.Errorf("error parsing validator index: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("index", index).Warn("validator attestations data: error converting index parameter from string to int") + http.Error(w, "Error: Invalid index parameter", http.StatusBadRequest) return } @@ -1050,14 +1050,14 @@ func ValidatorAttestations(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator attestations data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseInt(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator attestations data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } @@ -1147,14 +1147,14 @@ func ValidatorWithdrawals(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator withdrawals data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator withdrawals data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } @@ -1234,8 +1234,8 @@ func ValidatorSlashings(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator slashings data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } @@ -1506,15 +1506,15 @@ func ValidatorHistory(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator history data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator history data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } @@ -1838,20 +1838,20 @@ func ValidatorSync(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data draw-parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator sync data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start start-parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator sync data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length length-parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validator sync data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/validators.go b/handlers/validators.go index 9b2986641d..c98ca93f00 100644 --- a/handlers/validators.go +++ b/handlers/validators.go @@ -183,13 +183,13 @@ func parseValidatorsDataQueryParams(r *http.Request) (*ValidatorsDataQueryParams draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) + logger.WithError(err).WithField("route", r.URL.String()).Warn("parse validators data query params: error converting draw parameter from string to int") return nil, err } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) + logger.WithError(err).WithField("route", r.URL.String()).Warn("parse validators data query params: error converting start parameter from string to int") return nil, err } if start > 10000 { @@ -199,7 +199,7 @@ func parseValidatorsDataQueryParams(r *http.Request) (*ValidatorsDataQueryParams length, err := strconv.ParseInt(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) + logger.WithError(err).WithField("route", r.URL.String()).Warn("parse validators data query params: error converting length parameter from string to int") return nil, err } if length < 0 { @@ -233,8 +233,8 @@ func ValidatorsData(w http.ResponseWriter, r *http.Request) { dataQuery, err := parseValidatorsDataQueryParams(r) if err != nil { - logger.Errorf("error parsing query-data: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + // the only way this happens is if strconv.ParseUint fails, which is almost certainly a client error + http.Error(w, "Error: Invalid query parameters", http.StatusBadRequest) return } diff --git a/handlers/validators_leaderboard.go b/handlers/validators_leaderboard.go index 64dcbc9b1a..362d167ccb 100644 --- a/handlers/validators_leaderboard.go +++ b/handlers/validators_leaderboard.go @@ -38,38 +38,23 @@ func ValidatorsLeaderboardData(w http.ResponseWriter, r *http.Request) { if len(search) > 128 { search = search[:128] } - // var searchIndex *uint64 - // index, err := strconv.ParseUint(search, 10, 64) - // if err == nil { - // searchIndex = &index - // } - - // var searchPubkeyExact *string - // var searchPubkeyLike *string - // if searchPubkeyExactRE.MatchString(search) { - // pubkey := strings.ToLower(strings.Replace(search, "0x", "", -1)) - // searchPubkeyExact = &pubkey - // } else if searchPubkeyLikeRE.MatchString(search) { - // pubkey := strings.ToLower(strings.Replace(search, "0x", "", -1)) - // searchPubkeyLike = &pubkey - // } draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators leaderboard data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators leaderboard data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators leaderboard data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/validators_slashings.go b/handlers/validators_slashings.go index ca152a572f..2906712995 100644 --- a/handlers/validators_slashings.go +++ b/handlers/validators_slashings.go @@ -34,21 +34,21 @@ func ValidatorsSlashingsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators slashings data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators slashings data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("validators slashings data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { diff --git a/handlers/withdrawals.go b/handlers/withdrawals.go index 1edecba419..a3445fa3e2 100644 --- a/handlers/withdrawals.go +++ b/handlers/withdrawals.go @@ -59,15 +59,15 @@ func WithdrawalsData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("withdrawals data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("withdrawals data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } if start > 10000 { @@ -75,8 +75,8 @@ func WithdrawalsData(w http.ResponseWriter, r *http.Request) { } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("withdrawals data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 { @@ -234,14 +234,14 @@ func BLSChangeData(w http.ResponseWriter, r *http.Request) { draw, err := strconv.ParseUint(q.Get("draw"), 10, 64) if err != nil { - logger.Errorf("error converting datatables data parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("bls changes data: error converting draw parameter from string to int") + http.Error(w, "Error: Invalid draw parameter", http.StatusBadRequest) return } start, err := strconv.ParseUint(q.Get("start"), 10, 64) if err != nil { - logger.Errorf("error converting datatables start parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("bls changes data: error converting start parameter from string to int") + http.Error(w, "Error: Invalid start parameter", http.StatusBadRequest) return } if start > 10000 { @@ -250,8 +250,8 @@ func BLSChangeData(w http.ResponseWriter, r *http.Request) { } length, err := strconv.ParseUint(q.Get("length"), 10, 64) if err != nil { - logger.Errorf("error converting datatables length parameter from string to int: %v", err) - http.Error(w, "Internal server error", http.StatusServiceUnavailable) + logger.WithError(err).WithField("route", r.URL.String()).Warn("bls changes data: error converting length parameter from string to int") + http.Error(w, "Error: Invalid length parameter", http.StatusBadRequest) return } if length > 100 {