xanzy / go-gitlab

GitLab Go SDK
Apache License 2.0
2.39k stars 947 forks source link

Ignore response body during HEAD request error handling #1919

Closed vntw closed 4 months ago

vntw commented 5 months ago

Fixes #1047

This improves the error handling of a HEAD request response. It avoids trying to parse the body entirely. To handle the error, you can still check for a *gitlab.ErrorResponse:

_, _, err := gitlabClient.RepositoryFiles.GetFileMetaData(1, "not-there.txt", &gitlab.GetFileMetaDataOptions{Ref: gitlab.Ptr("main")})
if err != nil {
    var errResp *gitlab.ErrorResponse
    if errors.As(err, &errResp) {
        log.Println(errResp.Response.StatusCode)
    } else {
        log.Println(err)
    }
}