use errors.As to extract odataError (#3690)
casting only the top level error to an odataError will slice out useful data when the odataError is wrapped, stacked, or otherwise nested. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🐛 Bugfix #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
c7ce9f4c0e
commit
df100b9b3b
@ -227,7 +227,7 @@ func hasErrorCode(err error, codes ...errorCode) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var oDataError *odataerrors.ODataError
|
||||
var oDataError odataerrors.ODataErrorable
|
||||
if !errors.As(err, &oDataError) {
|
||||
return false
|
||||
}
|
||||
@ -252,12 +252,12 @@ func Wrap(ctx context.Context, e error, msg string) *clues.Err {
|
||||
return nil
|
||||
}
|
||||
|
||||
odErr, ok := e.(odataerrors.ODataErrorable)
|
||||
if !ok {
|
||||
var oDataError odataerrors.ODataErrorable
|
||||
if !errors.As(e, &oDataError) {
|
||||
return clues.Wrap(e, msg).WithClues(ctx)
|
||||
}
|
||||
|
||||
mainMsg, data, innerMsg := errData(odErr)
|
||||
mainMsg, data, innerMsg := errData(oDataError)
|
||||
|
||||
if len(mainMsg) > 0 {
|
||||
e = clues.Stack(e, clues.New(mainMsg))
|
||||
@ -273,12 +273,12 @@ func Stack(ctx context.Context, e error) *clues.Err {
|
||||
return nil
|
||||
}
|
||||
|
||||
odErr, ok := e.(odataerrors.ODataErrorable)
|
||||
if !ok {
|
||||
var oDataError *odataerrors.ODataError
|
||||
if !errors.As(e, &oDataError) {
|
||||
return clues.Stack(e).WithClues(ctx)
|
||||
}
|
||||
|
||||
mainMsg, data, innerMsg := errData(odErr)
|
||||
mainMsg, data, innerMsg := errData(oDataError)
|
||||
|
||||
if len(mainMsg) > 0 {
|
||||
e = clues.Stack(e, clues.New(mainMsg))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user