Skip to content

Commit

Permalink
Fix: return 400 on unknown address
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 10, 2024
1 parent 03ae983 commit 3d325ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/api/handler/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ func (handler *AddressHandler) getIdByHash(ctx context.Context, hash []byte, add

switch len(addressId) {
case 0:
return 0, errors.Errorf("can't find address: %s", address)
return 0, errors.Wrap(errUnknownAddress, address)
case 1:
return addressId[0], nil
default:
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handler/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
var (
errInvalidHashLength = errors.New("invalid hash: should be 32 bytes length")
errInvalidAddress = errors.New("invalid address")
errUnknownAddress = errors.New("unknown address")
errCancelRequest = "pq: canceling statement due to user request"
)

Expand Down Expand Up @@ -61,7 +62,7 @@ func handleError(c echo.Context, err error, noRows NoRows) error {
if noRows.IsNoRows(err) {
return c.NoContent(http.StatusNoContent)
}
if errors.Is(err, errInvalidAddress) {
if errors.Is(err, errInvalidAddress) || errors.Is(err, errUnknownAddress) {
return badRequestError(c, err)
}
return internalServerError(c, err)
Expand Down

0 comments on commit 3d325ca

Please sign in to comment.