Skip to content

Commit 9d58dab

Browse files
errors Improve the error that is returned when a response cannot be unmarshalled as JSON
1 parent 152e5fd commit 9d58dab

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

changes/20250407100502.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `errors` Improve the error that is returned when a response cannot be unmarshalled as JSON

utils/api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414

1515
"github.com/ARM-software/embedded-development-services-client-utils/utils/errors"
16+
"github.com/ARM-software/golang-utils/utils/commonerrors"
1617
"github.com/ARM-software/golang-utils/utils/parallelisation"
1718
"github.com/ARM-software/golang-utils/utils/reflection"
1819
)
@@ -40,7 +41,7 @@ func CheckAPICallSuccess(ctx context.Context, errorContext string, resp *_http.R
4041
if resp != nil {
4142
statusCode = resp.StatusCode
4243
errorDetails, subErr := errors.FetchAPIErrorDescriptionWithContext(ctx, resp)
43-
if subErr != nil {
44+
if commonerrors.Ignore(subErr, commonerrors.ErrMarshalling) != nil {
4445
err = subErr
4546
return
4647
}

utils/errors/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515

1616
"github.com/ARM-software/embedded-development-services-client/client"
17+
"github.com/ARM-software/golang-utils/utils/commonerrors"
1718
"github.com/ARM-software/golang-utils/utils/parallelisation"
1819
"github.com/ARM-software/golang-utils/utils/reflection"
1920
"github.com/ARM-software/golang-utils/utils/safeio"
@@ -51,6 +52,7 @@ func FetchAPIErrorDescriptionWithContext(ctx context.Context, resp *_http.Respon
5152
}
5253
if err != nil {
5354
message = string(bytes)
55+
err = commonerrors.WrapError(commonerrors.ErrMarshalling, err, "error occurred when unmarshalling response")
5456
return
5557
}
5658
apiErrorMessage := strings.Builder{}

0 commit comments

Comments
 (0)