Documentation
¶
Overview ¶
Package api provides common helpers related to API calls.
Index ¶
- func CallAndCheckSuccess[T any](ctx context.Context, errorContext string, ...) (result *T, err error)
- func CheckAPICallSuccess(ctx context.Context, errorContext string, resp *http.Response, apiErr error) (err error)
- func GenericCallAndCheckSuccess[T any](ctx context.Context, errorContext string, ...) (result T, err error)
- func IsCallSuccessful(r *http.Response) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallAndCheckSuccess ¶ added in v1.15.0
func CallAndCheckSuccess[T any](ctx context.Context, errorContext string, apiCallFunc func(ctx context.Context) (*T, *http.Response, error)) (result *T, err error)
CallAndCheckSuccess is a wrapper for making an API call and then checking success with `CheckAPICallSuccess` errorContext corresponds to the description of what led to the error if error there is e.g. `Failed adding a user`. apiCallFunc corresponds to a generic function that will be called to make the API call
func CheckAPICallSuccess ¶
func CheckAPICallSuccess(ctx context.Context, errorContext string, resp *http.Response, apiErr error) (err error)
CheckAPICallSuccess verifies whether an API response is successful or not and if not, populates an error with all the information needed. errorContext corresponds to the description of what led to the error if error there is e.g. `Failed adding a user`. resp corresponds to the HTTP response from a certain endpoint. The body of such response is not closed by this function. apiErr corresponds to the error which may be returned by the HTTP client when calling the endpoint.
func GenericCallAndCheckSuccess ¶ added in v1.16.0
func GenericCallAndCheckSuccess[T any](ctx context.Context, errorContext string, apiCallFunc func(ctx context.Context) (T, *http.Response, error)) (result T, err error)
GenericCallAndCheckSuccess is similar to CallAndCheckSuccess but for function returning interfaces rather than concrete types. T must be an interface. errorContext corresponds to the description of what led to the error if error there is e.g. `Failed adding a user`. apiCallFunc corresponds to a generic function that will be called to make the API call
func IsCallSuccessful ¶
IsCallSuccessful determines whether an API response is successful or not
Types ¶
This section is empty.