diff --git a/eosws/db.go b/eosws/db.go index 3af66261..63d47093 100755 --- a/eosws/db.go +++ b/eosws/db.go @@ -122,22 +122,6 @@ func (db *TRXDB) GetTransactions(ctx context.Context, ids []string) (out []*pbco // ultra-keisuke-kanao --- BLOCK-2123 eosws - runtime error: slice bounds out of range --- func (db *TRXDB) ListTransactionsForBlockID(ctx context.Context, blockID string, startKey string, limit int) (out *mdl.TransactionList, err error) { - defer func() { - recoveredErr := recover() - if recoveredErr == nil { - return - } - - switch v := recoveredErr.(type) { - case error: - err = fmt.Errorf("%w", v) - case string, fmt.Stringer: - err = fmt.Errorf("%s", v) - default: - err = fmt.Errorf("%v", v) - } - }() - if limit < 1 { return &mdl.TransactionList{ Cursor: opaqueCursor(startKey), diff --git a/eosws/rest/block.go b/eosws/rest/block.go index 79f4cfc1..d21fa06a 100644 --- a/eosws/rest/block.go +++ b/eosws/rest/block.go @@ -15,6 +15,7 @@ package rest import ( + "fmt" "net/http" "net/url" "strconv" @@ -166,6 +167,35 @@ func GetBlockHandler(db eosws.DB) http.Handler { func GetBlockTransactionsHandler(db eosws.DB) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + defer func() { + recoveredErr := recover() + if recoveredErr == nil { + return + } + var errMsg string = "unknown error2" + switch v := recoveredErr.(type) { + case string: + errMsg = v + case error: + errMsg = v.Error() + default: + errMsg = fmt.Sprintf("%v", v) + } + eosws.WriteError(w, r, derr.HTTPInternalServerError(ctx, nil, derr.ErrorCode("unexpected_error"), "An unexpected error occurred.", errMsg)) + ////////////////////////////////////////////////////////////////////// + // Billable event on REST API endpoint + // WARNING: Ingress / Egress bytess is taken care by the middleware + ////////////////////////////////////////////////////////////////////// + dmetering.EmitWithContext(dmetering.Event{ + Source: "eosws", + Kind: "REST API - eosq", + Method: "/v0/blocks/{blockID}/transactions", + RequestsCount: 1, + ResponsesCount: 1, + }, ctx) + ////////////////////////////////////////////////////////////////////// + return + }() vars := mux.Vars(r) id := vars["blockID"] @@ -194,7 +224,7 @@ func GetBlockTransactionsHandler(db eosws.DB) http.Handler { dbTransactionList, err := db.ListTransactionsForBlockID(r.Context(), id, cursor, limit) if err != nil { - eosws.WriteError(w, r, derr.Wrap(err, "failed to get block transactions")) + eosws.WriteError(w, r, derr.HTTPInternalServerError(ctx, nil, derr.ErrorCode("unexpected_error"), "failed to get block transactions")) return } diff --git a/eosws/rest/simplesearch.go b/eosws/rest/simplesearch.go index e2e50f1f..1a1c7ef4 100644 --- a/eosws/rest/simplesearch.go +++ b/eosws/rest/simplesearch.go @@ -15,6 +15,7 @@ package rest import ( + "fmt" "net/http" "net/url" "regexp" @@ -35,6 +36,37 @@ func SimpleSearchHandler(db eosws.DB, blockmetaClient *pbblockmeta.Client) http. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() query := r.FormValue("q") + defer func() { + recoveredErr := recover() + if recoveredErr == nil { + return + } + var errMsg string = "unknown error1" + switch v := recoveredErr.(type) { + case string: + errMsg = v + case error: + errMsg = v.Error() + default: + errMsg = fmt.Sprintf("%v", v) + } + eosws.WriteError(w, r, derr.HTTPInternalServerError(ctx, nil, derr.ErrorCode("unexpected_error"), "An unexpected error occurred.", errMsg)) + + ////////////////////////////////////////////////////////////////////// + // Billable event on REST API endpoint + // WARNING: Ingress / Egress bytess is taken care by the middleware + ////////////////////////////////////////////////////////////////////// + dmetering.EmitWithContext(dmetering.Event{ + Source: "eosws", + Kind: "REST API - eosq", + Method: "/v0/simple_search", + RequestsCount: 1, + ResponsesCount: 1, + }, ctx) + ////////////////////////////////////////////////////////////////////// + return + }() + if query == "" { eosws.WriteError(w, r, derr.RequestValidationError(ctx, url.Values{"q": []string{"query parameter should not be empty"}})) //////////////////////////////////////////////////////////////////////