Skip to content

Commit a514525

Browse files
committed
use errors.As
1 parent c320987 commit a514525

1 file changed

Lines changed: 5 additions & 20 deletions

File tree

libs/diag/sdk_error.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,21 @@ import (
99
"github.com/databricks/databricks-sdk-go/apierr"
1010
)
1111

12-
func findApiErr(e error) *apierr.APIError {
13-
for {
14-
cast, ok := e.(*apierr.APIError)
15-
if ok {
16-
return cast
17-
}
18-
19-
inner := errors.Unwrap(e)
20-
if inner == nil {
21-
break
22-
}
23-
e = inner
24-
}
25-
return nil
26-
}
27-
2812
func FormatAPIErrorSummary(e error) string {
29-
apiErr := findApiErr(e)
30-
if apiErr == nil {
13+
var apiErr *apierr.APIError
14+
if !errors.As(e, &apiErr) {
3115
return e.Error()
3216
}
3317
extra := strings.TrimSpace(fmt.Sprintf("%d %s", apiErr.StatusCode, apiErr.ErrorCode))
3418
return e.Error() + " (" + extra + ")"
3519
}
3620

3721
func FormatAPIErrorDetails(e error) string {
38-
apiErr := findApiErr(e)
39-
if apiErr == nil {
22+
var apiErr *apierr.APIError
23+
if !errors.As(e, &apiErr) {
4024
return ""
4125
}
26+
4227
endpoint := "n/a"
4328
httpStatus := ""
4429
w := apiErr.ResponseWrapper

0 commit comments

Comments
 (0)