github.com/MetalBlockchain/subnet-evm@v0.4.9/rpc/errors.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. 2 // 3 // This file is a derived work, based on the go-ethereum library whose original 4 // notices appear below. 5 // 6 // It is distributed under a license compatible with the licensing terms of the 7 // original code from which it is derived. 8 // 9 // Much love to the original authors for their work. 10 // ********** 11 // Copyright 2015 The go-ethereum Authors 12 // This file is part of the go-ethereum library. 13 // 14 // The go-ethereum library is free software: you can redistribute it and/or modify 15 // it under the terms of the GNU Lesser General Public License as published by 16 // the Free Software Foundation, either version 3 of the License, or 17 // (at your option) any later version. 18 // 19 // The go-ethereum library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 // GNU Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public License 25 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 26 27 package rpc 28 29 import "fmt" 30 31 // HTTPError is returned by client operations when the HTTP status code of the 32 // response is not a 2xx status. 33 type HTTPError struct { 34 StatusCode int 35 Status string 36 Body []byte 37 } 38 39 func (err HTTPError) Error() string { 40 if len(err.Body) == 0 { 41 return err.Status 42 } 43 return fmt.Sprintf("%v: %s", err.Status, err.Body) 44 } 45 46 // Error wraps RPC errors, which contain an error code in addition to the message. 47 type Error interface { 48 Error() string // returns the message 49 ErrorCode() int // returns the code 50 } 51 52 // A DataError contains some data in addition to the error message. 53 type DataError interface { 54 Error() string // returns the message 55 ErrorData() interface{} // returns the error data 56 } 57 58 // Error types defined below are the built-in JSON-RPC errors. 59 60 var ( 61 _ Error = new(methodNotFoundError) 62 _ Error = new(subscriptionNotFoundError) 63 _ Error = new(parseError) 64 _ Error = new(invalidRequestError) 65 _ Error = new(invalidMessageError) 66 _ Error = new(invalidParamsError) 67 ) 68 69 const defaultErrorCode = -32000 70 71 type methodNotFoundError struct{ method string } 72 73 func (e *methodNotFoundError) ErrorCode() int { return -32601 } 74 75 func (e *methodNotFoundError) Error() string { 76 return fmt.Sprintf("the method %s does not exist/is not available", e.method) 77 } 78 79 type subscriptionNotFoundError struct{ namespace, subscription string } 80 81 func (e *subscriptionNotFoundError) ErrorCode() int { return -32601 } 82 83 func (e *subscriptionNotFoundError) Error() string { 84 return fmt.Sprintf("no %q subscription in %s namespace", e.subscription, e.namespace) 85 } 86 87 // Invalid JSON was received by the server. 88 type parseError struct{ message string } 89 90 func (e *parseError) ErrorCode() int { return -32700 } 91 92 func (e *parseError) Error() string { return e.message } 93 94 // received message isn't a valid request 95 type invalidRequestError struct{ message string } 96 97 func (e *invalidRequestError) ErrorCode() int { return -32600 } 98 99 func (e *invalidRequestError) Error() string { return e.message } 100 101 // received message is invalid 102 type invalidMessageError struct{ message string } 103 104 func (e *invalidMessageError) ErrorCode() int { return -32700 } 105 106 func (e *invalidMessageError) Error() string { return e.message } 107 108 // unable to decode supplied params, or an invalid number of parameters 109 type invalidParamsError struct{ message string } 110 111 func (e *invalidParamsError) ErrorCode() int { return -32602 } 112 113 func (e *invalidParamsError) Error() string { return e.message }