Skip to content

Commit e1c1a07

Browse files
committed
refactor(webpush): Remove nested error checks
Signed-off-by: 0xsysr3ll <[email protected]>
1 parent ff828d3 commit e1c1a07

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

server/lib/notifications/agents/webpush.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ interface WebPushError extends Error {
3131
response?: {
3232
body?: string | unknown;
3333
};
34-
errors?: {
35-
statusCode?: number;
36-
status?: number;
37-
message?: string;
38-
body?: string | unknown;
39-
}[];
4034
}
4135

4236
class WebPushAgent
@@ -203,34 +197,11 @@ class WebPushAgent
203197
notificationPayload
204198
);
205199
} catch (e) {
206-
// Extract status code from error or nested errors (for AggregateError)
207200
const webPushError = e as WebPushError;
208-
let statusCode = webPushError.statusCode || webPushError.status;
209-
let errorMessage = webPushError.message || String(e);
210-
let errorBody = webPushError.body || webPushError.response?.body;
211-
212-
// Handle AggregateError - check nested errors for status codes
213-
if (e instanceof AggregateError || webPushError.errors) {
214-
const errors = webPushError.errors || [];
215-
for (const nestedError of errors) {
216-
const nestedStatusCode =
217-
nestedError?.statusCode || nestedError?.status;
218-
if (nestedStatusCode) {
219-
statusCode = nestedStatusCode;
220-
}
221-
if (nestedError?.message && !errorMessage) {
222-
errorMessage = nestedError.message;
223-
}
224-
if (nestedError?.body && !errorBody) {
225-
errorBody = nestedError.body;
226-
}
227-
}
228-
}
201+
const statusCode = webPushError.statusCode || webPushError.status;
202+
const errorMessage = webPushError.message || String(e);
229203

230-
// Permanent failure status codes per RFC 8030:
231-
// - 410 Gone: Subscription expired/invalid (Section 6.2)
232-
// - 404 Not Found: Subscription expired (Section 7.3)
233-
// All other errors (429 rate limiting, network issues, etc.) are transient
204+
// RFC 8030: 410/404 are permanent failures, others are transient
234205
const isPermanentFailure = statusCode === 410 || statusCode === 404;
235206

236207
logger.error(
@@ -247,8 +218,6 @@ class WebPushAgent
247218
}
248219
);
249220

250-
// Only remove subscription for permanent failures
251-
// Transient errors (rate limiting, network issues, etc.) should not remove the subscription
252221
if (isPermanentFailure) {
253222
await userPushSubRepository.remove(pushSub);
254223
}

0 commit comments

Comments
 (0)