Skip to content

Commit

Permalink
Fix: unuseful error notifications (#981)
Browse files Browse the repository at this point in the history
* More informative errors on view execution (#979)

* Remove mumbainet (#980)

* Partitioning. Operation hash to bytes. Remove mumbainet

* Fix: saving big map diffs

* Fix: do not send execute view errors to sentry
  • Loading branch information
aopoltorzhicky committed Jul 16, 2023
1 parent 49c5ad0 commit e04773b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
10 changes: 8 additions & 2 deletions cmd/api/handlers/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import (
"github.com/baking-bad/bcdhub/internal/bcd/ast"
"github.com/baking-bad/bcdhub/internal/logger"
"github.com/baking-bad/bcdhub/internal/models"
"github.com/baking-bad/bcdhub/internal/noderpc"
sentrygin "github.com/getsentry/sentry-go/gin"
"github.com/gin-gonic/gin"
jsoniter "github.com/json-iterator/go"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func skipError(err error) bool {
return errors.Is(err, noderpc.ErrNodeRPCError)
}

func handleError(c *gin.Context, repo models.GeneralRepository, err error, code int) bool {
if err == nil {
return false
Expand All @@ -24,12 +29,13 @@ func handleError(c *gin.Context, repo models.GeneralRepository, err error, code
err = errors.New("invalid authentication")
case 0:
code = getErrorCode(err, repo)
if code == http.StatusInternalServerError {
if code == http.StatusInternalServerError && !skipError(err) {
if hub := sentrygin.GetHubFromContext(c); hub != nil {
hub.CaptureMessage(err.Error())
}
logger.Err(err)
}

logger.Err(err)
}

c.AbortWithStatusJSON(code, getErrorMessage(err, repo))
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/handlers/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handlers

import (
"context"
"errors"
"io"
"net/http"
"time"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/baking-bad/bcdhub/internal/models/contract"
"github.com/baking-bad/bcdhub/internal/views"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions configs/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ indexer:
networks:
mainnet:
receiver_threads: 5
# ghostnet:
# receiver_threads: 10
ghostnet:
receiver_threads: 10
nairobinet:
receiver_threads: 10
connections:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
ports:
- 127.0.0.1:${POSTGRES_PORT}:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
Expand Down
2 changes: 1 addition & 1 deletion internal/noderpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ func (e InvalidNodeResponse) Is(target error) bool {
// Errors
var (
ErrInvalidStatusCode = errors.New("invalid status code")
ErrNodeRPCError = "Node RPC error"
ErrNodeRPCError = errors.New("Node RPC error")
)
6 changes: 3 additions & 3 deletions internal/noderpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (rpc *NodeRPC) checkStatusCode(resp *http.Response, checkStatusCode bool) e

func (rpc *NodeRPC) parseResponse(resp *http.Response, checkStatusCode bool, uri string, response interface{}) error {
if err := rpc.checkStatusCode(resp, checkStatusCode); err != nil {
return errors.Wrapf(err, "%s (%s)", ErrNodeRPCError, uri)
return fmt.Errorf("%w (%s): %w", ErrNodeRPCError, uri, err)
}

return json.NewDecoder(resp.Body).Decode(response)
Expand Down Expand Up @@ -185,7 +185,7 @@ func (rpc *NodeRPC) getRaw(ctx context.Context, uri string) ([]byte, error) {
defer resp.Body.Close()

if err := rpc.checkStatusCode(resp, true); err != nil {
return nil, errors.Wrapf(err, "%s (%s)", ErrNodeRPCError, uri)
return nil, fmt.Errorf("%w (%s): %w", ErrNodeRPCError, uri, err)
}
return io.ReadAll(resp.Body)
}
Expand All @@ -198,7 +198,7 @@ func (rpc *NodeRPC) post(ctx context.Context, uri string, data interface{}, chec
}
defer resp.Body.Close()

return rpc.parseResponse(resp, checkStatusCode, "", response)
return rpc.parseResponse(resp, checkStatusCode, uri, response)
}

// Block - returns block
Expand Down

0 comments on commit e04773b

Please sign in to comment.