Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"regexp"
Expand All @@ -26,7 +27,7 @@ var (
// Err is used to write errors.
Err io.Writer
// jsonContentTypeRe is used to match Content-Type which contains JSON.
jsonContentTypeRe = regexp.MustCompile(`^application/([[:alpha:]]+\+)?json$`)
jsonContentTypeRe = regexp.MustCompile(`^application/([[:alpha:]]+\+)?json($|;)`)
)

const msgWelcomePleaseConfigure = `
Expand Down Expand Up @@ -122,7 +123,7 @@ func decodedAPIError(resp *http.Response) error {
strings.Join(apiError.Error.PossibleTrackIDs, ", "),
)
}
return fmt.Errorf(apiError.Error.Message)
return errors.New(apiError.Error.Message)
}
return fmt.Errorf("unexpected API response: %d", resp.StatusCode)
}
4 changes: 4 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func TestDecodeErrorResponse(t *testing.T) {
response: errorResponse418("application/json", `{"error": {"type": "json", "valid": no}}`),
wantMessage: "failed to parse API error response: invalid character 'o' in literal null (expecting 'u')",
},
{
response: errorResponse418("application/json; charset=utf-8", `{"error": {"type": "track_ambiguous", "message": "message", "possible_track_ids": ["a", "b"]}}`),
wantMessage: "message: a, b",
},
{
response: errorResponse418("application/json", `{"error": {"type": "track_ambiguous", "message": "message", "possible_track_ids": ["a", "b"]}}`),
wantMessage: "message: a, b",
Expand Down
Loading