mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
graphql: errorcode int
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
8927c49bdd
commit
8cb7cff8d9
1 changed files with 17 additions and 9 deletions
|
|
@ -18,30 +18,34 @@
|
||||||
package graphql
|
package graphql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errBlockInvariant = errors.New("block objects must be instantiated with at least one of num or hash")
|
errBlockInvariant = invalidParamsError("block objects must be instantiated with at least one of num or hash")
|
||||||
errInvalidBlockRange = errors.New("invalid from and to block combination: from > to")
|
errInvalidBlockRange = invalidParamsError("invalid from and to block combination: from > to")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
errcodeDefault = -32600
|
||||||
|
errcodeInvalidParams = -32602
|
||||||
)
|
)
|
||||||
|
|
||||||
type graphQLError struct {
|
type graphQLError struct {
|
||||||
Code string `json:"code"`
|
Code int
|
||||||
Message string `json:"message"`
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error implements the github.com/graph-gophers/graphql-go.ResolverError interface.
|
// Error implements the github.com/graph-gophers/graphql-go.ResolverError interface.
|
||||||
func (e *graphQLError) Error() string {
|
func (e *graphQLError) Error() string {
|
||||||
return fmt.Sprintf("error [%s]: %s", e.Code, e.Message)
|
return fmt.Sprintf("error [%d]: %s", e.Code, e.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions implements the github.com/graph-gophers/graphql-go.ResolverError interface.
|
// Extensions implements the github.com/graph-gophers/graphql-go.ResolverError interface.
|
||||||
func (e *graphQLError) Extensions() map[string]interface{} {
|
func (e *graphQLError) Extensions() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"code": e.Code,
|
"errorCode": e.Code,
|
||||||
"message": e.Message,
|
"errorMessage": e.Message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,5 +54,9 @@ func asGraphQLError(err error) error {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &graphQLError{Code: "-32602", Message: err.Error()}
|
return &graphQLError{Code: errcodeDefault, Message: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func invalidParamsError(msg string) error {
|
||||||
|
return &graphQLError{Code: errcodeInvalidParams, Message: msg}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue