diff --git a/client.go b/client.go index b268de49..8c015537 100644 --- a/client.go +++ b/client.go @@ -154,7 +154,10 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error } url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken) - req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload)) + req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload)) + if err != nil { + return nil, err + } if c.Token != nil { c.setTokenHeader(req) diff --git a/client_test.go b/client_test.go index 974a4ab1..c32be0d0 100644 --- a/client_test.go +++ b/client_test.go @@ -102,6 +102,15 @@ func TestClientBadTransportError(t *testing.T) { assert.Nil(t, res) } +func TestClientBadDeviceToken(t *testing.T) { + n := &apns.Notification{} + n.DeviceToken = "DGw\aOoD+HwSroh#Ug]%xzd]" + n.Payload = []byte(`{"aps":{"alert":"Hello!"}}`) + res, err := mockClient("https://api.push.apple.com").Push(n) + assert.Error(t, err) + assert.Nil(t, res) +} + func TestClientNameToCertificate(t *testing.T) { crt, _ := certificate.FromP12File("certificate/_fixtures/certificate-valid.p12", "") client := apns.NewClient(crt)