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,
Message: err.Error(),
}}
var ec Error
if errors.As(err, &ec) {
msg.Error.Code = ec.ErrorCode()
var rpcError Error
if errors.As(err, &rpcError) {
msg.Error.Code = rpcError.ErrorCode()
}
var de DataError
if errors.As(err, &de) {
// Type assert on rpcError to ensure that both code and data come from the same error object.
de, ok := rpcError.(DataError)
if ok {
msg.Error.Data = de.ErrorData()
}
return msg