Skip to content

Commit

Permalink
fix: improve artifactory error handling (#3546)
Browse files Browse the repository at this point in the history
closes #3543

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Nov 12, 2022
1 parent c4fd0a0 commit 778f099
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/pipe/artifactory/artifactory.go
Expand Up @@ -79,7 +79,7 @@ func checkResponse(r *h.Response) error {
if err == nil && data != nil {
err := json.Unmarshal(data, errorResponse)
if err != nil {
return err
return fmt.Errorf("unexpected error: %w: %s", err, string(data))
}
}
return errorResponse
Expand Down
8 changes: 2 additions & 6 deletions internal/pipe/artifactory/artifactory_test.go
Expand Up @@ -461,11 +461,7 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
requireHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")

w.WriteHeader(http.StatusUnauthorized)
fmt.Fprint(w, `...{
"errors" : [ {
...
} ]
}`)
fmt.Fprint(w, `<body><h1>error</h1></body>`)
})

ctx := context.New(config.Project{
Expand Down Expand Up @@ -495,7 +491,7 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
})

require.NoError(t, Pipe{}.Default(ctx))
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: invalid character '.' looking for beginning of value`)
require.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: unexpected error: invalid character '<' looking for beginning of value: <body><h1>error</h1></body>`)
}

func TestRunPipe_FileNotFound(t *testing.T) {
Expand Down

0 comments on commit 778f099

Please sign in to comment.