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
12 changes: 9 additions & 3 deletions social/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
)

const (
socialCodeFriendListFull = 1028 // Observed when the People list limit would be exceeded.
socialCodeRestricted = 1011 // Observed for forbidden relationship operations.
socialCodeRestrictedPrivacy = 1049 // Observed for target-user privacy restrictions.
socialCodeFriendListFull = 1028 // Observed when the People list limit would be exceeded.
socialCodeRestricted = 1011 // Observed for forbidden relationship operations.
socialCodeRestrictedPrivacy = 1049 // Observed for target-user privacy restrictions.
socialCodeBulkOperationLimit = 1050 // Observed when a bulk relationship request contains too many users.
)

var (
Expand All @@ -23,6 +24,9 @@ var (
ErrFriendListFull = errors.New("xsapi/social: friend list full")
// ErrFriendRestricted matches privacy, enforcement, or relationship restriction responses.
ErrFriendRestricted = errors.New("xsapi/social: friend restricted")
// ErrBulkOperationLimit matches responses indicating a bulk relationship
// request contains more users than the service accepts.
ErrBulkOperationLimit = errors.New("xsapi/social: bulk operation limit")
)

// ResponseError carries error details returned by the Xbox Live Social and
Expand Down Expand Up @@ -71,6 +75,8 @@ func (e *ResponseError) Is(target error) bool {
return e.Code == socialCodeFriendListFull
case ErrFriendRestricted:
return e.Code == socialCodeRestricted || e.Code == socialCodeRestrictedPrivacy
case ErrBulkOperationLimit:
return e.Code == socialCodeBulkOperationLimit
default:
return false
}
Expand Down
15 changes: 15 additions & 0 deletions social/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func TestResponseErrorMatchesCategories(t *testing.T) {
{name: "rate limited", err: &ResponseError{StatusCode: http.StatusTooManyRequests}, target: ErrRateLimited, want: true},
{name: "retry after without rate limit", err: &ResponseError{StatusCode: http.StatusInternalServerError, RetryAfter: time.Second}, target: ErrRateLimited},
{name: "friend list full", err: &ResponseError{Code: 1028}, target: ErrFriendListFull, want: true},
{name: "bulk operation limit", err: &ResponseError{Code: 1050}, target: ErrBulkOperationLimit, want: true},
{name: "restricted", err: &ResponseError{Code: 1011}, target: ErrFriendRestricted, want: true},
{name: "restricted alternate", err: &ResponseError{Code: 1049}, target: ErrFriendRestricted, want: true},
}
Expand All @@ -175,6 +176,20 @@ func TestResponseErrorMatchesCategories(t *testing.T) {
}
}

func TestAddFriendsReturnsBulkOperationLimit(t *testing.T) {
client := New(&http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
return response(req, http.StatusBadRequest, `{"code":1050,"description":"too many users"}`), nil
})}, nil, xsts.UserInfo{}, nil)

_, err := client.AddFriends(context.Background(), []string{"123", "456"})
if err == nil {
t.Fatal("AddFriends returned nil error")
}
if !errors.Is(err, ErrBulkOperationLimit) {
t.Fatalf("errors.Is(ErrBulkOperationLimit) = false for %T: %v", err, err)
}
}

func TestResponseErrorPreservesMetadataWhenBodyReadFails(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "https://peoplehub.xboxlive.com/users/me/people/social", nil)
if err != nil {
Expand Down