From 87d0ec17de1b8a6e2ddd08e247ca7e40063a5b59 Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Sun, 22 Oct 2023 20:29:13 +0200 Subject: [PATCH] Fix: status code on bad request (#996) --- cmd/api/handlers/account.go | 2 +- cmd/api/handlers/bigmap.go | 16 ++++++++-------- cmd/api/handlers/code.go | 4 ++-- cmd/api/handlers/contract.go | 8 ++++---- cmd/api/handlers/entrypoints.go | 10 +++++----- cmd/api/handlers/events.go | 4 ++-- cmd/api/handlers/fork.go | 2 +- cmd/api/handlers/global_constants.go | 12 ++++++------ cmd/api/handlers/helpers.go | 4 ++-- cmd/api/handlers/mempool.go | 2 +- cmd/api/handlers/middleware.go | 2 +- cmd/api/handlers/migrations.go | 2 +- cmd/api/handlers/operations.go | 16 ++++++++-------- cmd/api/handlers/prepare.go | 1 - cmd/api/handlers/run_code.go | 8 ++++---- cmd/api/handlers/smart_rollup.go | 4 ++-- cmd/api/handlers/stats.go | 4 ++-- cmd/api/handlers/storage.go | 16 ++++++++-------- cmd/api/handlers/tickets.go | 14 +++++++------- cmd/api/handlers/views.go | 8 ++++---- cmd/api/main.go | 2 +- 21 files changed, 70 insertions(+), 71 deletions(-) diff --git a/cmd/api/handlers/account.go b/cmd/api/handlers/account.go index ae42b96e0..c348c245a 100644 --- a/cmd/api/handlers/account.go +++ b/cmd/api/handlers/account.go @@ -28,7 +28,7 @@ func GetInfo() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getAccountRequest - if err := c.BindUri(&req); err != nil { + if err := c.ShouldBindUri(&req); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, Error{Message: err.Error()}) return } diff --git a/cmd/api/handlers/bigmap.go b/cmd/api/handlers/bigmap.go index 63a7815b3..82dbc6cab 100644 --- a/cmd/api/handlers/bigmap.go +++ b/cmd/api/handlers/bigmap.go @@ -35,7 +35,7 @@ func GetBigMap() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getBigMapRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -143,7 +143,7 @@ func GetBigMapHistory() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getBigMapRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -182,11 +182,11 @@ func GetBigMapKeys() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getBigMapRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var pageReq bigMapSearchRequest - if err := c.BindQuery(&pageReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&pageReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -238,12 +238,12 @@ func GetBigMapByKeyHash() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getBigMapByKeyHashRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var pageReq pageableRequest - if err := c.BindQuery(&pageReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&pageReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -291,7 +291,7 @@ func GetCurrentBigMapKeyHash() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getBigMapByKeyHashRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -345,7 +345,7 @@ func GetBigMapDiffCount() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getBigMapRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/code.go b/cmd/api/handlers/code.go index cacd3111f..6ff255cdd 100644 --- a/cmd/api/handlers/code.go +++ b/cmd/api/handlers/code.go @@ -32,11 +32,11 @@ func GetContractCode() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractCodeRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } - if err := c.BindQuery(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/contract.go b/cmd/api/handlers/contract.go index 8bc201499..54168ac58 100644 --- a/cmd/api/handlers/contract.go +++ b/cmd/api/handlers/contract.go @@ -29,12 +29,12 @@ func GetContract() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var args withStatsRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } @@ -85,12 +85,12 @@ func GetSameContracts() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var page pageableRequest - if err := c.BindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/entrypoints.go b/cmd/api/handlers/entrypoints.go index 850487773..0a60d2254 100644 --- a/cmd/api/handlers/entrypoints.go +++ b/cmd/api/handlers/entrypoints.go @@ -35,7 +35,7 @@ func GetEntrypoints() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } @@ -92,11 +92,11 @@ func GetEntrypointData() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var reqData getEntrypointDataRequest - if err := c.BindJSON(&reqData); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindJSON(&reqData); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -144,12 +144,12 @@ func GetEntrypointSchema() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var esReq entrypointSchemaRequest - if err := c.BindQuery(&esReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&esReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/events.go b/cmd/api/handlers/events.go index 1fb726087..5febf134c 100644 --- a/cmd/api/handlers/events.go +++ b/cmd/api/handlers/events.go @@ -28,12 +28,12 @@ func ListEvents() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getAccountRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var page pageableRequest - if err := c.BindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/fork.go b/cmd/api/handlers/fork.go index bf83b7b24..db29ed9cb 100644 --- a/cmd/api/handlers/fork.go +++ b/cmd/api/handlers/fork.go @@ -17,7 +17,7 @@ import ( func ForkContract(ctxs config.Contexts) gin.HandlerFunc { return func(c *gin.Context) { var req forkRequest - if err := c.BindJSON(&req); handleError(c, ctxs.Any().Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindJSON(&req); handleError(c, ctxs.Any().Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/global_constants.go b/cmd/api/handlers/global_constants.go index fe5efa46b..c21b785a9 100644 --- a/cmd/api/handlers/global_constants.go +++ b/cmd/api/handlers/global_constants.go @@ -28,7 +28,7 @@ func GetGlobalConstant() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getGlobalConstantRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -71,7 +71,7 @@ func ListGlobalConstants() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var args globalConstantsListRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -110,12 +110,12 @@ func GetContractGlobalConstants() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var args pageableRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -154,11 +154,11 @@ func GetGlobalConstantContracts() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var args globalConstantsContractsRequest - if err := c.BindUri(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/helpers.go b/cmd/api/handlers/helpers.go index bdb3be2ba..1a9c05000 100644 --- a/cmd/api/handlers/helpers.go +++ b/cmd/api/handlers/helpers.go @@ -15,12 +15,12 @@ func ContractsHelpers() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getByNetwork - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var args findContract - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/mempool.go b/cmd/api/handlers/mempool.go index b1e5dd4b6..58f05867d 100644 --- a/cmd/api/handlers/mempool.go +++ b/cmd/api/handlers/mempool.go @@ -34,7 +34,7 @@ func GetMempool() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getAccountRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } diff --git a/cmd/api/handlers/middleware.go b/cmd/api/handlers/middleware.go index 571576b70..6a2c0d45d 100644 --- a/cmd/api/handlers/middleware.go +++ b/cmd/api/handlers/middleware.go @@ -12,7 +12,7 @@ import ( func NetworkMiddleware(ctxs config.Contexts) gin.HandlerFunc { return func(c *gin.Context) { var req getByNetwork - if err := c.BindUri(&req); err != nil { + if err := c.ShouldBindUri(&req); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, Error{Message: err.Error()}) return } diff --git a/cmd/api/handlers/migrations.go b/cmd/api/handlers/migrations.go index 4814fc181..eee33890d 100644 --- a/cmd/api/handlers/migrations.go +++ b/cmd/api/handlers/migrations.go @@ -29,7 +29,7 @@ func GetContractMigrations() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } diff --git a/cmd/api/handlers/operations.go b/cmd/api/handlers/operations.go index ece60333c..49540abf9 100644 --- a/cmd/api/handlers/operations.go +++ b/cmd/api/handlers/operations.go @@ -34,12 +34,12 @@ func GetOperation() gin.HandlerFunc { any := ctxs.Any() var req OPGRequest - if err := c.BindUri(&req); handleError(c, any.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, any.Storage, err, http.StatusBadRequest) { return } var queryReq opgRequest - if err := c.BindQuery(&queryReq); handleError(c, any.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&queryReq); handleError(c, any.Storage, err, http.StatusBadRequest) { return } @@ -119,7 +119,7 @@ func GetImplicitOperation() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req ImplicitOperationRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -155,7 +155,7 @@ func GetOperationErrorLocation() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getOperationByIDRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -195,7 +195,7 @@ func GetOperationDiff() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getOperationByIDRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } operation, err := ctx.Operations.GetByID(c.Request.Context(), req.ID) @@ -241,12 +241,12 @@ func GetOperationGroups() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getAccountRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var args opgForAddressRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -283,7 +283,7 @@ func GetByHashAndCounter() gin.HandlerFunc { ctxs := c.MustGet("contexts").(config.Contexts) var req OperationGroupContentRequest - if err := c.BindUri(&req); handleError(c, ctxs.Any().Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctxs.Any().Storage, err, http.StatusNotFound) { return } diff --git a/cmd/api/handlers/prepare.go b/cmd/api/handlers/prepare.go index d9e6cffe7..6cf6e4916 100644 --- a/cmd/api/handlers/prepare.go +++ b/cmd/api/handlers/prepare.go @@ -240,7 +240,6 @@ func setParatemetersWithType(params *types.Parameters, parameter *ast.TypedAst, op.Parameters, err = tree.ToMiguel() if err != nil { if !tezerrors.HasGasExhaustedError(op.Errors) { - helpers.CatchErrorSentry(err) return err } } diff --git a/cmd/api/handlers/run_code.go b/cmd/api/handlers/run_code.go index 3d550e959..ae676ddc2 100644 --- a/cmd/api/handlers/run_code.go +++ b/cmd/api/handlers/run_code.go @@ -27,11 +27,11 @@ func RunOperation() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var reqRunOp runOperationRequest - if err := c.BindJSON(&reqRunOp); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindJSON(&reqRunOp); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -135,11 +135,11 @@ func RunCode() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var reqRunCode runCodeRequest - if err := c.BindJSON(&reqRunCode); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindJSON(&reqRunCode); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/smart_rollup.go b/cmd/api/handlers/smart_rollup.go index 6749d6960..541b744ba 100644 --- a/cmd/api/handlers/smart_rollup.go +++ b/cmd/api/handlers/smart_rollup.go @@ -27,7 +27,7 @@ func GetSmartRollup() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getSmartRollupRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -71,7 +71,7 @@ func ListSmartRollups() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var args smartRollupListRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/stats.go b/cmd/api/handlers/stats.go index b63515cc1..4e0ad159d 100644 --- a/cmd/api/handlers/stats.go +++ b/cmd/api/handlers/stats.go @@ -82,12 +82,12 @@ func RecentlyCalledContracts() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getByNetwork - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var page pageableRequest - if err := c.BindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&page); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/storage.go b/cmd/api/handlers/storage.go index 8d5375fa6..48f3404bf 100644 --- a/cmd/api/handlers/storage.go +++ b/cmd/api/handlers/storage.go @@ -34,12 +34,12 @@ func GetContractStorage() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var sReq storageRequest - if err := c.BindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -103,11 +103,11 @@ func GetContractStorageRaw() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var sReq storageRequest - if err := c.BindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } storage, err := getDeffattedStorage(c, ctx, req.Address, int64(sReq.Level)) @@ -144,11 +144,11 @@ func GetContractStorageRich() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var sReq storageRequest - if err := c.BindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&sReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } storage, err := getDeffattedStorage(c, ctx, req.Address, int64(sReq.Level)) @@ -208,11 +208,11 @@ func GetContractStorageSchema() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var ssReq storageSchemaRequest - if err := c.BindQuery(&ssReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&ssReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/handlers/tickets.go b/cmd/api/handlers/tickets.go index 3ad36f2de..07f96caa6 100644 --- a/cmd/api/handlers/tickets.go +++ b/cmd/api/handlers/tickets.go @@ -33,12 +33,12 @@ func GetContractTicketUpdates() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var args ticketUpdatesRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -84,12 +84,12 @@ func GetContractTickets() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } var args pageableRequest - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } @@ -112,7 +112,7 @@ func GetTicketUpdatesForOperation() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getOperationByIDRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } operation, err := ctx.Operations.GetByID(c.Request.Context(), req.ID) @@ -138,13 +138,13 @@ func GetTicketBalancesForAccount() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getAccountRequest - if err := c.BindUri(&req); err != nil { + if err := c.ShouldBindUri(&req); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, Error{Message: err.Error()}) return } var args ticketBalancesRequest - if err := c.BindQuery(&args); err != nil { + if err := c.ShouldBindQuery(&args); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, Error{Message: err.Error()}) return } diff --git a/cmd/api/handlers/views.go b/cmd/api/handlers/views.go index 13327d710..697b5f222 100644 --- a/cmd/api/handlers/views.go +++ b/cmd/api/handlers/views.go @@ -42,12 +42,12 @@ func GetViewsSchema() gin.HandlerFunc { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var args getViewsArgs - if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } @@ -203,11 +203,11 @@ func ExecuteView() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.MustGet("context").(*config.Context) var req getContractRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { + if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { return } var execView executeViewRequest - if err := c.BindJSON(&execView); handleError(c, ctx.Storage, err, http.StatusBadRequest) { + if err := c.ShouldBindJSON(&execView); handleError(c, ctx.Storage, err, http.StatusBadRequest) { return } diff --git a/cmd/api/main.go b/cmd/api/main.go index 6b28860d8..1d5d0243c 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -269,7 +269,7 @@ func (api *app) Close() error { // Run - func (api *app) Run() { if err := api.Router.Run(api.Config.API.Bind); err != nil { - if errors.Is(err, http.ErrServerClosed) { + if errors.Is(err, http.ErrServerClosed) || errors.Is(err, context.Canceled) { return } log.Err(err).Msg("API running error")