Skip to content

Commit 65d7518

Browse files
committed
Add a check in CallAndCheckSuccess for response unmarshalling issues
1 parent adb3ff1 commit 65d7518

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

changes/20250423114015.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:gear: Add a check in CallAndCheckSuccess for response unmarshalling issues

utils/api/api.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func CheckAPICallSuccess(ctx context.Context, errorContext string, resp *_http.R
6262
// CallAndCheckSuccess is a wrapper for making an API call and then checking success with `CheckAPICallSuccess`
6363
// errorContext corresponds to the description of what led to the error if error there is e.g. `Failed adding a user`.
6464
// apiCallFunc corresponds to a generic function that will be called to make the API call
65-
func CallAndCheckSuccess[T any](ctx context.Context, errorContext string, apiCallFunc func(ctx context.Context) (T, *_http.Response, error)) (result T, err error) {
65+
func CallAndCheckSuccess[T any](ctx context.Context, errorContext string, apiCallFunc func(ctx context.Context) (*T, *_http.Response, error)) (result *T, err error) {
6666
if err = parallelisation.DetermineContextError(ctx); err != nil {
6767
return
6868
}
@@ -76,5 +76,12 @@ func CallAndCheckSuccess[T any](ctx context.Context, errorContext string, apiCal
7676
return
7777
}
7878

79+
if result != nil {
80+
if reflection.IsEmpty(result) {
81+
err = commonerrors.New(commonerrors.ErrMarshalling, "unmarshalled response is empty")
82+
return
83+
}
84+
}
85+
7986
return
8087
}

0 commit comments

Comments
 (0)