forked from cerc-io/plugeth
rpc: improve error codes for internal server errors (#25678)
This changes the error code returned by the RPC server in certain situations: - handler panic: code -32603 - result marshaling error: code -32603 - attempt to subscribe via HTTP: code -32001 In all of the above cases, the server previously returned the default error code -32000. Co-authored-by: Nicholas Zhao <nicholas.zhao@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
co-authored by
Nicholas Zhao
Felix Lange
parent
06151eb581
commit
610cf02c4a
+2
-3
@@ -104,15 +104,14 @@ func (msg *jsonrpcMessage) errorResponse(err error) *jsonrpcMessage {
|
||||
func (msg *jsonrpcMessage) response(result interface{}) *jsonrpcMessage {
|
||||
enc, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
// TODO: wrap with 'internal server error'
|
||||
return msg.errorResponse(err)
|
||||
return msg.errorResponse(&internalServerError{errcodeMarshalError, err.Error()})
|
||||
}
|
||||
return &jsonrpcMessage{Version: vsn, ID: msg.ID, Result: enc}
|
||||
}
|
||||
|
||||
func errorMessage(err error) *jsonrpcMessage {
|
||||
msg := &jsonrpcMessage{Version: vsn, ID: null, Error: &jsonError{
|
||||
Code: defaultErrorCode,
|
||||
Code: errcodeDefault,
|
||||
Message: err.Error(),
|
||||
}}
|
||||
ec, ok := err.(Error)
|
||||
|
||||
Reference in New Issue
Block a user