Skip to content

Commit

Permalink
Merge pull request #2537 from gobitfly/BIDS-2417/Wrong_user_input_errors
Browse files Browse the repository at this point in the history
Bids 2417/wrong user input errors
  • Loading branch information
Eisei24 authored Sep 21, 2023
2 parents e2294cb + 3460087 commit a0a6efb
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 259 deletions.
2 changes: 1 addition & 1 deletion cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func main() {
router.HandleFunc("/validator/{pubkey}/deposits", handlers.ValidatorDeposits).Methods("GET")
router.HandleFunc("/validator/{index}/slashings", handlers.ValidatorSlashings).Methods("GET")
router.HandleFunc("/validator/{index}/effectiveness", handlers.ValidatorAttestationInclusionEffectiveness).Methods("GET")
router.HandleFunc("/validator/{pubkey}/save", handlers.ValidatorSave).Methods("POST")
router.HandleFunc("/validator/{pubkey}/name", handlers.SaveValidatorName).Methods("POST")
router.HandleFunc("/watchlist/add", handlers.UsersModalAddValidator).Methods("POST")
router.HandleFunc("/validator/{pubkey}/remove", handlers.UserValidatorWatchlistRemove).Methods("POST")
router.HandleFunc("/validator/{index}/stats", handlers.ValidatorStatsTable).Methods("GET")
Expand Down
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ func saveBlocks(blocks map[uint64]map[string]*types.Block, tx *sqlx.Tx, forceSlo
b.Signature,
b.RandaoReveal,
b.Graffiti,
utils.GraffitiToSring(b.Graffiti),
utils.GraffitiToString(b.Graffiti),
b.Eth1Data.DepositRoot,
b.Eth1Data.DepositCount,
b.Eth1Data.BlockHash,
Expand Down
4 changes: 2 additions & 2 deletions handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ func SetDataTableStateChanges(w http.ResponseWriter, r *http.Request) {
settings := types.DataTableSaveState{}
err = json.NewDecoder(r.Body).Decode(&settings)
if err != nil {
utils.LogError(err, errMsgPrefix+", could not parse body", 0, errFields)
w.WriteHeader(http.StatusInternalServerError)
logger.Warnf(errMsgPrefix+", could not parse body for tableKey %v: %v", tableKey, err)
w.WriteHeader(http.StatusBadRequest)
return
}

Expand Down
12 changes: 6 additions & 6 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ func DashboardDataBalanceCombined(w http.ResponseWriter, r *http.Request) {
if len(param) != 0 {
days, err := strconv.ParseUint(param, 10, 32)
if err != nil {
logger.Error(err)
http.Error(w, "Error: invalid days parameter", http.StatusBadRequest)
logger.Warnf("error parsing days: %v", err)
http.Error(w, "Error: invalid parameter days", http.StatusBadRequest)
return
}
lastStatsDay, err := services.LatestExportedStatisticDay()
Expand Down Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}

Expand Down
3 changes: 2 additions & 1 deletion handlers/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"eth2-exporter/types"
"eth2-exporter/utils"
"fmt"
"math"
"net/http"
"strconv"
"strings"
Expand All @@ -29,7 +30,7 @@ func Epoch(w http.ResponseWriter, r *http.Request) {
var epochFutureTemplate = templates.GetTemplate(epochFutureTemplateFiles...)
var epochNotFoundTemplate = templates.GetTemplate(epochNotFoundTemplateFiles...)

const MaxEpochValue = 4294967296 // we only render a page for epochs up to this value
const MaxEpochValue = math.MaxUint32 + 1 // we only render a page for epochs up to this value

w.Header().Set("Content-Type", "text/html")
vars := mux.Vars(r)
Expand Down
12 changes: 6 additions & 6 deletions handlers/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", 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.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
12 changes: 6 additions & 6 deletions handlers/eth1Blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter start", 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.Warnf("error converting datatables length parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
24 changes: 12 additions & 12 deletions handlers/eth1Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", 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.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", 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.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
2 changes: 1 addition & 1 deletion handlers/eth1tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Eth1TransactionTx(w http.ResponseWriter, r *http.Request) {

txHash, err := hex.DecodeString(strings.ReplaceAll(txHashString, "0x", ""))
if err != nil {
logger.Errorf("error parsing tx hash %v: %v", txHashString, err)
logger.Warnf("error parsing tx hash %v: %v", txHashString, err)
data = InitPageData(w, r, "blockchain", path, title, txNotFoundTemplateFiles)
txTemplate = txNotFoundTemplate
} else {
Expand Down
12 changes: 6 additions & 6 deletions handlers/eth2Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", 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.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", 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.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
3 changes: 2 additions & 1 deletion handlers/graffitiwall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"eth2-exporter/db"
"eth2-exporter/templates"
"eth2-exporter/types"
"eth2-exporter/utils"
"net/http"
)

Expand All @@ -21,7 +22,7 @@ func Graffitiwall(w http.ResponseWriter, r *http.Request) {
err = db.ReaderDb.Select(&graffitiwallData, "SELECT DISTINCT ON (x, y) x, y, color, slot, validator from graffitiwall ORDER BY x, y, slot DESC")

if err != nil {
logger.Errorf("error retrieving block tree data: %v", err)
utils.LogError(err, "error retrieving graffitiwall data", 0)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
}
Expand Down
Loading

0 comments on commit a0a6efb

Please sign in to comment.