Skip to content

Commit e7fac1c

Browse files
Added warning logs when a misconfigured configuration is used in release mode
1 parent 36128eb commit e7fac1c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sources/WebPush/WebPushManager.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ public actor WebPushManager: Sendable {
101101
logger: Logger,
102102
executor: Executor
103103
) {
104-
assert(vapidConfiguration.validityDuration <= vapidConfiguration.expirationDuration, "The validity duration must be earlier than the expiration duration since it represents when the VAPID Authorization token will be refreshed ahead of it expiring.");
105-
assert(vapidConfiguration.expirationDuration <= .hours(24), "The expiration duration must be less than 24 hours or else push endpoints will reject messages sent to them.");
106-
precondition(!vapidConfiguration.keys.isEmpty, "VAPID.Configuration must have keys specified.")
104+
if vapidConfiguration.validityDuration > vapidConfiguration.expirationDuration {
105+
assertionFailure("The validity duration must be earlier than the expiration duration since it represents when the VAPID Authorization token will be refreshed ahead of it expiring.")
106+
logger.error("The validity duration must be earlier than the expiration duration since it represents when the VAPID Authorization token will be refreshed ahead of it expiring. Run your application server with the same configuration in debug mode to catch this.")
107+
}
108+
if vapidConfiguration.expirationDuration > .hours(24) {
109+
assertionFailure("The expiration duration must be less than 24 hours or else push endpoints will reject messages sent to them.")
110+
logger.error("The expiration duration must be less than 24 hours or else push endpoints will reject messages sent to them. Run your application server with the same configuration in debug mode to catch this.")
111+
}
112+
precondition(!vapidConfiguration.keys.isEmpty, "VAPID.Configuration must have keys specified. Please report this as a bug with reproduction steps if encountered: https://github.com/mochidev/swift-webpush/issues.")
107113

108114
self.vapidConfiguration = vapidConfiguration
109115
let allKeys = vapidConfiguration.keys + Array(vapidConfiguration.deprecatedKeys ?? [])

0 commit comments

Comments
 (0)