From fd648cad3a59fa22ecb27639f9cfe5847807cdc9 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Fri, 11 Nov 2022 12:03:39 -0500 Subject: [PATCH] [render skip] notif tester --- internal/api/devices.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/api/devices.go b/internal/api/devices.go index f844cbb..b3bc0d8 100644 --- a/internal/api/devices.go +++ b/internal/api/devices.go @@ -83,12 +83,15 @@ func (a *api) testDeviceHandler(w http.ResponseWriter, r *http.Request) { client = client.Production() } - if _, err := client.Push(notification); err != nil { + res, err := client.Push(notification) + if err != nil { a.logger.Info("failed to send test notification", zap.Error(err)) a.errorResponse(w, r, 500, err) - return + } else if !res.Sent() { + a.errorResponse(w, r, 422, fmt.Errorf("errror sending notification: %d: %s", res.StatusCode, res.Reason)) + } else { + w.WriteHeader(http.StatusOK) } - w.WriteHeader(http.StatusOK) } func (a *api) deleteDeviceHandler(w http.ResponseWriter, r *http.Request) {