Skip to content

Commit 5274aaf

Browse files
committed
rfq: refine error code handling
Avoids a blunt cast of the wire code, and also refrains from relaying the full Error() message to the peer.
1 parent bbd3afe commit 5274aaf

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

rfq/negotiator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func createCustomRejectErr(err error) rfqmsg.RejectErr {
513513
// The rejection message will state that the oracle doesn't
514514
// support the asset.
515515
case ErrUnsupportedOracleAsset:
516-
msg := oracleError.Error()
516+
msg := oracleError.Msg
517517
return rfqmsg.ErrRejectWithCustomMsg(msg)
518518

519519
// The rejection message will be opaque, with the error

rfq/oracle.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (r *RpcPriceOracle) QuerySellPrice(ctx context.Context,
371371
return &OracleResponse{
372372
Err: &OracleError{
373373
Msg: result.Error.Message,
374-
Code: OracleErrorCode(result.Error.Code),
374+
Code: marshallErrorCode(result.Error.Code),
375375
},
376376
}, nil
377377

@@ -380,6 +380,19 @@ func (r *RpcPriceOracle) QuerySellPrice(ctx context.Context,
380380
}
381381
}
382382

383+
// marshallErrorCode marshalls an over-the-wire error code into an
384+
// OracleErrorCode.
385+
func marshallErrorCode(code oraclerpc.ErrorCode) OracleErrorCode {
386+
switch code {
387+
case oraclerpc.ErrorCode_ERROR_UNSPECIFIED:
388+
return ErrUnspecifiedOracleError
389+
case oraclerpc.ErrorCode_ERROR_UNSUPPORTED:
390+
return ErrUnsupportedOracleAsset
391+
default:
392+
return ErrUnspecifiedOracleError
393+
}
394+
}
395+
383396
// QueryBuyPrice returns a buy price for the given asset amount.
384397
func (r *RpcPriceOracle) QueryBuyPrice(ctx context.Context,
385398
assetSpecifier asset.Specifier, assetMaxAmt fn.Option[uint64],
@@ -483,7 +496,7 @@ func (r *RpcPriceOracle) QueryBuyPrice(ctx context.Context,
483496
return &OracleResponse{
484497
Err: &OracleError{
485498
Msg: result.Error.Message,
486-
Code: OracleErrorCode(result.Error.Code),
499+
Code: marshallErrorCode(result.Error.Code),
487500
},
488501
}, nil
489502

0 commit comments

Comments
 (0)