Take data from the same object

This commit is contained in:
Piotr Mikołajczyk 2026-05-06 14:49:34 +02:00
parent 2c5136b794
commit c471e3c571
No known key found for this signature in database
GPG key ID: 67B506351FF7CBC8

View file

@ -126,12 +126,13 @@ func errorMessage(err error) *jsonrpcMessage {
Code: errcodeDefault, Code: errcodeDefault,
Message: err.Error(), Message: err.Error(),
}} }}
var ec Error var rpcError Error
if errors.As(err, &ec) { if errors.As(err, &rpcError) {
msg.Error.Code = ec.ErrorCode() msg.Error.Code = rpcError.ErrorCode()
} }
var de DataError // Type assert on rpcError to ensure that both code and data come from the same error object.
if errors.As(err, &de) { de, ok := rpcError.(DataError)
if ok {
msg.Error.Data = de.ErrorData() msg.Error.Data = de.ErrorData()
} }
return msg return msg