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
9 changes: 5 additions & 4 deletions internal/cli/episode_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io"
"net/http"
"strings"

publicapi "github.com/listenbox/listenbox-cli/publicapi"
Expand Down Expand Up @@ -77,12 +78,12 @@ func deleteEpisode(
}
if response == nil || response.Status202 == nil {
if response != nil {
switch {
case response.Status401:
switch response.StatusCode {
case http.StatusUnauthorized:
return fmt.Errorf("delete episode %q: authentication failed; run listenbox login", episodeID)
case response.Status403:
case http.StatusForbidden:
return fmt.Errorf("delete episode %q: only the current team owner may delete it", episodeID)
case response.Status404:
case http.StatusNotFound:
return fmt.Errorf("delete episode %q: episode not found", episodeID)
}
return fmt.Errorf("delete episode %q returned HTTP status %d", episodeID, response.StatusCode)
Expand Down
9 changes: 5 additions & 4 deletions internal/cli/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strings"

Expand Down Expand Up @@ -131,13 +132,13 @@ func handleImportRSSResponse(
response.Status402.CurrentEntitlement,
response.Status402.PricingUrl,
)
case response.Status401:
case response.StatusCode == http.StatusUnauthorized:
return fmt.Errorf("import RSS feed %q: authentication failed; run listenbox login", sourceURL)
case response.Status403:
case response.StatusCode == http.StatusForbidden:
return fmt.Errorf("import RSS feed %q: API key lacks show:create scope", sourceURL)
case response.Status409 && slugExplicit:
case response.StatusCode == http.StatusConflict && slugExplicit:
return fmt.Errorf("import RSS feed %q: requested slug %q conflicts", sourceURL, requestedSlug)
case response.Status409:
case response.StatusCode == http.StatusConflict:
return fmt.Errorf("import RSS feed %q: import choice conflicts", sourceURL)
default:
return fmt.Errorf("import RSS feed %q returned HTTP status %d", sourceURL, response.StatusCode)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func isUnauthorized(err error) bool {
}

func responseUnauthorized(response *publicapi.CreateCLIAuthorizationResponse) bool {
return response != nil && response.Status401
return response != nil && response.StatusCode == http.StatusUnauthorized
}

func validateVerificationURL(value string) error {
Expand Down
26 changes: 8 additions & 18 deletions internal/cli/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -118,7 +119,6 @@ func listShowMembers(
if response.Status200 == nil {
return teamManagementResponseError(
"list show members", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status404,
)
}
if err := writeShowMembers(stdout, response.Status200.Members); err != nil {
Expand All @@ -143,7 +143,6 @@ func listTeamMembers(
if response.Status200 == nil {
return teamManagementResponseError(
"list members", response.StatusCode, response.Status400,
response.Status401, response.Status403, false,
)
}
if err := writeTeamMembers(stdout, response.Status200.Members); err != nil {
Expand Down Expand Up @@ -294,7 +293,6 @@ func inviteShowMember(
if response.Status201 == nil {
return publicapi.PendingShowInvitation{}, teamManagementResponseError(
"invite show member", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status409,
)
}
return *response.Status201, nil
Expand All @@ -321,7 +319,6 @@ func inviteTeamMember(
if response.Status201 == nil {
return publicapi.PendingTeamInvitation{}, teamManagementResponseError(
"invite member", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status409,
)
}
return *response.Status201, nil
Expand Down Expand Up @@ -397,10 +394,9 @@ func updateShowMemberRole(
if response == nil {
return errors.New("change show member role returned no response")
}
if !response.Status204 {
if response.StatusCode != http.StatusNoContent {
return teamManagementResponseError(
"change show member role", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status404,
)
}
_, err = fmt.Fprintf(stdout, "Changed show member %s to %s.\n", memberID, role)
Expand All @@ -426,10 +422,9 @@ func updateTeamMemberRole(
if response == nil {
return errors.New("change member role returned no response")
}
if !response.Status204 {
if response.StatusCode != http.StatusNoContent {
return teamManagementResponseError(
"change member role", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status404,
)
}
_, err = fmt.Fprintf(stdout, "Changed member %s to %s.\n", memberID, role)
Expand Down Expand Up @@ -502,10 +497,9 @@ func removeShowMember(
if response == nil {
return errors.New("remove show member returned no response")
}
if !response.Status204 {
if response.StatusCode != http.StatusNoContent {
return teamManagementResponseError(
"remove show member", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status404,
)
}
_, err = fmt.Fprintf(stdout, "Removed show member %s.\n", memberID)
Expand All @@ -525,10 +519,9 @@ func removeTeamMember(
if response == nil {
return errors.New("remove member returned no response")
}
if !response.Status204 {
if response.StatusCode != http.StatusNoContent {
return teamManagementResponseError(
"remove member", response.StatusCode, response.Status400,
response.Status401, response.Status403, response.Status404,
)
}
_, err = fmt.Fprintf(stdout, "Removed member %s.\n", memberID)
Expand Down Expand Up @@ -567,18 +560,15 @@ func teamManagementResponseError(
action string,
status int,
validation *publicapi.ValidationErr,
unauthorized bool,
forbidden bool,
conflictOrNotFound bool,
) error {
switch {
case validation != nil:
return fmt.Errorf("%s: %s", action, validation.Message)
case unauthorized:
case status == http.StatusUnauthorized:
return fmt.Errorf("%s: authentication failed; run listenbox login", action)
case forbidden:
case status == http.StatusForbidden:
return fmt.Errorf("%s: team owner permission is required", action)
case conflictOrNotFound:
case status == http.StatusConflict || status == http.StatusNotFound:
return fmt.Errorf("%s: target is unavailable", action)
default:
return fmt.Errorf("%s returned HTTP status %d", action, status)
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/show_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"strings"

publicapi "github.com/listenbox/listenbox-cli/publicapi"
Expand Down Expand Up @@ -73,11 +74,11 @@ func validateShowDeletionResponse(slug string, response *publicapi.CreateShowDel
switch {
case response.Status400 != nil:
return nil, fmt.Errorf("delete show %q: %s", slug, response.Status400.Message)
case response.Status401:
case response.StatusCode == http.StatusUnauthorized:
return nil, fmt.Errorf("delete show %q: authentication failed; run listenbox login", slug)
case response.Status403:
case response.StatusCode == http.StatusForbidden:
return nil, fmt.Errorf("delete show %q: only the current show owner may delete it", slug)
case response.Status404:
case response.StatusCode == http.StatusNotFound:
return nil, fmt.Errorf("delete show %q: show not found", slug)
default:
return nil, fmt.Errorf("delete show %q returned HTTP status %d", slug, response.StatusCode)
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/shows.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func handleListShowsResponse(stdout io.Writer, response *publicapi.ListShowsResp
return nil
case response.Status400 != nil:
return fmt.Errorf("list shows: %s", response.Status400.Message)
case response.Status401:
case response.StatusCode == http.StatusUnauthorized:
return errors.New("list shows: authentication failed; run listenbox login")
default:
return fmt.Errorf("list shows returned HTTP status %d", response.StatusCode)
Expand Down Expand Up @@ -293,11 +293,11 @@ func handleCreateShowResponse(
return nil
case response.Status400 != nil:
return fmt.Errorf("create show %q: %s", slug, response.Status400.Message)
case response.Status401:
case response.StatusCode == http.StatusUnauthorized:
return fmt.Errorf("create show %q: authentication failed; run listenbox login", slug)
case response.Status403:
case response.StatusCode == http.StatusForbidden:
return fmt.Errorf("create show %q: API key lacks show:create scope", slug)
case response.Status409:
case response.StatusCode == http.StatusConflict:
return fmt.Errorf("create show: slug %q already exists", slug)
default:
return fmt.Errorf("create show %q returned HTTP status %d", slug, response.StatusCode)
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net/http"
"strings"

publicapi "github.com/listenbox/listenbox-cli/publicapi"
Expand Down Expand Up @@ -39,7 +40,7 @@ func authStatus(
switch {
case response.Status200 != nil:
return printAuthStatus(stdout, *response.Status200)
case response.Status401:
case response.StatusCode == http.StatusUnauthorized:
return fmt.Errorf(
"auth status against %q: authentication failed; run listenbox login",
config.apiOrigin,
Expand Down
Loading