Skip to content

Commit

Permalink
Add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaptoss committed Sep 27, 2024
1 parent 20b79a1 commit bce1e56
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/service/handlers/create_abstraction_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"bytes"
"errors"
"fmt"
"math/big"
"net/http"

Expand Down Expand Up @@ -75,6 +76,11 @@ func CreateAbstractionAccount(w http.ResponseWriter, r *http.Request) {

addr, err = Abstraction(r).CreateAccount(r.Context(), nullifierBytes)
if err != nil {
errData := ErrorData(err)
if errData != nil {
log = log.WithField("data", fmt.Sprintf("%+v", errData))
}

log.WithError(err).Error("Failed to create abstraction account")
ape.RenderErr(w, problems.InternalError())
return
Expand Down
25 changes: 25 additions & 0 deletions internal/service/handlers/get_abstraction_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"bytes"
"errors"
"net/http"
"strings"

Expand Down Expand Up @@ -55,3 +56,27 @@ func GetAbstractionAccount(w http.ResponseWriter, r *http.Request) {
},
})
}

type EthJsonRpcErrorI interface {
Error() string
ErrorCode() int
ErrorData() interface{}
}

func ErrorData(err error) interface{} {
for err != nil {
uerr := errors.Unwrap(err)
if uerr == nil {
break
}

err = uerr
}
var cerr EthJsonRpcErrorI
ok := errors.As(err, &cerr)
if ok {
return cerr.ErrorData()
}

return nil
}

0 comments on commit bce1e56

Please sign in to comment.