Skip to content

Commit

Permalink
Account for changed error response from upstream lib
Browse files Browse the repository at this point in the history
The upstream gitlab library changed the way it handles 404s returned
from the GitLab instance in the way that it now simply returns a
sentinel error (see xanzy/go-gitlab@f49ba02#diff-044b5a63fdba539bf87d25040d91912aec34173e76af7b9e0f40d14da57edebeR973-R974)
for details.

We now need to check for that sentinel error explicitly and return an
appropriate gitprovider error type.

Signed-off-by: Max Jonas Werner <[email protected]>
  • Loading branch information
makkes committed Aug 15, 2024
1 parent cedb7a6 commit ca04066
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gitlab/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func handleHTTPError(err error) error {
if err == nil {
return nil
}

if err == gitlab.ErrNotFound {
return gitprovider.ErrNotFound
}

glErrorResponse := &gitlab.ErrorResponse{}
if errors.As(err, &glErrorResponse) {
httpErr := gitprovider.HTTPError{
Expand All @@ -240,10 +245,6 @@ func handleHTTPError(err error) error {
&gitprovider.InvalidCredentialsError{HTTPError: httpErr},
)
}
// Check for 404 Not Found
if glErrorResponse.Response.StatusCode == http.StatusNotFound {
return validation.NewMultiError(err, gitprovider.ErrNotFound)
}
// Check for already exists errors
if strings.Contains(glErrorResponse.Message, alreadyExistsMagicString) {
return validation.NewMultiError(err, gitprovider.ErrAlreadyExists)
Expand Down

0 comments on commit ca04066

Please sign in to comment.