Skip to main content

Error handling

Every SDK operation returns three values:

result, response, err := request.Execute()
ValueMeaning
resultDecoded response model (or stream / file for some endpoints)
responseUnderlying *http.Response when the server answered
errTransport, decoding, or API error
_, response, err := client.ProfileAPI.
MainApiV1GetMyProfileInfoGet(ctx).
Execute()
if err != nil {
if response != nil {
fmt.Printf("HTTP %d: %v\n", response.StatusCode, err)
} else {
fmt.Printf("request failed: %v\n", err)
}
return
}

GenericOpenAPIError

var apiError *analogwakatime.GenericOpenAPIError
if errors.As(err, &apiError) {
fmt.Println(string(apiError.Body()))
}

Timeout

requestContext, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

profile, _, err := client.ProfileAPI.
MainApiV1GetMyProfileInfoGet(requestContext).
Execute()