File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // VAPIDConfigurationError.swift
3+ // swift-webpush
4+ //
5+ // Created by Dimitri Bouniol on 2024-12-13.
6+ // Copyright © 2024 Mochi Development, Inc. All rights reserved.
7+ //
8+
9+ import Foundation
10+
11+ extension VAPID {
12+ /// An error encountered during ``VAPID/Configuration`` initialization or decoding.
13+ public struct ConfigurationError : LocalizedError , Hashable {
14+ enum Kind {
15+ case keysNotProvided
16+ }
17+
18+ var kind : Kind
19+
20+ /// VAPID keys not found during initialization.
21+ public static let keysNotProvided = Self ( kind: . keysNotProvided)
22+
23+ public var errorDescription : String ? {
24+ switch kind {
25+ case . keysNotProvided:
26+ " VAPID keys not found during initialization. "
27+ }
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -46,14 +46,14 @@ extension VoluntaryApplicationServerIdentification {
4646 contactInformation: ContactInformation ,
4747 expirationDuration: Duration = . hours( 22 ) ,
4848 validityDuration: Duration = . hours( 20 )
49- ) throws {
49+ ) throws ( ConfigurationError ) {
5050 self . primaryKey = primaryKey
5151 var keys = keys
5252 if let primaryKey {
5353 keys. insert ( primaryKey)
5454 }
5555 guard !keys. isEmpty
56- else { throw CancellationError ( ) } // TODO: No keys error
56+ else { throw . keysNotProvided }
5757
5858 self . keys = keys
5959 var deprecatedKeys = deprecatedKeys ?? [ ]
@@ -88,14 +88,14 @@ extension VoluntaryApplicationServerIdentification {
8888 primaryKey: Key ? ,
8989 keys: Set < Key > ,
9090 deprecatedKeys: Set < Key > ? = nil
91- ) throws {
91+ ) throws ( ConfigurationError ) {
9292 self . primaryKey = primaryKey
9393 var keys = keys
9494 if let primaryKey {
9595 keys. insert ( primaryKey)
9696 }
9797 guard !keys. isEmpty
98- else { throw CancellationError ( ) } // TODO: No keys error
98+ else { throw . keysNotProvided }
9999
100100 self . keys = keys
101101 var deprecatedKeys = deprecatedKeys ?? [ ]
You can’t perform that action at this time.
0 commit comments