Skip to content

Commit a46c503

Browse files
committed
custom errors
leaving these custom errors in the notifs package bc they won't be used anyhwere else
1 parent 726855f commit a46c503

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

backend/internal/service/notifications/service.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
8+
"fmt"
79
"log/slog"
810
"net/http"
911
"time"
@@ -14,6 +16,11 @@ import (
1416

1517
const expoPushURL = "https://exp.host/--/exponent-push-api/v2/push/send"
1618

19+
var (
20+
ErrExpoPushFailed = errors.New("expo push request failed")
21+
ErrExpoPushRejected = errors.New("expo push rejected by server")
22+
)
23+
1724
// NotificationSender is implemented by Service. Handlers that trigger
1825
// notifications depend on this interface for testability.
1926
type NotificationSender interface {
@@ -72,12 +79,12 @@ func (s *Service) sendExpoPush(tokens []string, title, body string) {
7279

7380
resp, err := s.client.Post(expoPushURL, "application/json", bytes.NewReader(payload))
7481
if err != nil {
75-
slog.Error("notifications: expo push failed", "err", err)
82+
slog.Error("notifications: expo push failed", "err", fmt.Errorf("%w: %w", ErrExpoPushFailed, err))
7683
return
7784
}
7885
defer resp.Body.Close()
7986

8087
if resp.StatusCode >= 400 {
81-
slog.Error("notifications: expo push returned error status", "status", resp.StatusCode)
88+
slog.Error("notifications: expo push rejected", "err", fmt.Errorf("%w: status %d", ErrExpoPushRejected, resp.StatusCode))
8289
}
8390
}

0 commit comments

Comments
 (0)