ducky/subscriptions
ducky/subscriptions/client/subscription.go
Return errors from responses in client. When the client makes a request, non-200 responses _are not_ considered errors. So we need to check the response.Errors property, and if it has errors, _then_ we consider the request to have an error. To make this happen, we created an httpErrors type that fulfills the error interface and just wraps the response Errors property. Then callers can type-cast it and interrogate it.
1 package client
3 import (
4 "code.secondbit.org/auth.hg"
6 "code.secondbit.org/ducky/subscriptions.hg"
7 "code.secondbit.org/ducky/subscriptions.hg/api"
8 )
10 func (c *Client) CreateSubscription(change subscriptions.SubscriptionChange) (subscriptions.Subscription, error) {
11 resp, err := c.Post("/subscriptions/", change, auth.Scopes{api.ScopeSubscription, api.ScopeSubscriptionAdmin}.Strings(), change.UserID)
12 if err != nil {
13 return subscriptions.Subscription{}, err
14 }
15 if len(resp.Subscriptions) < 1 {
16 return subscriptions.Subscription{}, subscriptions.ErrSubscriptionNotFound
17 }
18 return resp.Subscriptions[0], nil
19 }