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 {
46
46
contactInformation: ContactInformation ,
47
47
expirationDuration: Duration = . hours( 22 ) ,
48
48
validityDuration: Duration = . hours( 20 )
49
- ) throws {
49
+ ) throws ( ConfigurationError ) {
50
50
self . primaryKey = primaryKey
51
51
var keys = keys
52
52
if let primaryKey {
53
53
keys. insert ( primaryKey)
54
54
}
55
55
guard !keys. isEmpty
56
- else { throw CancellationError ( ) } // TODO: No keys error
56
+ else { throw . keysNotProvided }
57
57
58
58
self . keys = keys
59
59
var deprecatedKeys = deprecatedKeys ?? [ ]
@@ -88,14 +88,14 @@ extension VoluntaryApplicationServerIdentification {
88
88
primaryKey: Key ? ,
89
89
keys: Set < Key > ,
90
90
deprecatedKeys: Set < Key > ? = nil
91
- ) throws {
91
+ ) throws ( ConfigurationError ) {
92
92
self . primaryKey = primaryKey
93
93
var keys = keys
94
94
if let primaryKey {
95
95
keys. insert ( primaryKey)
96
96
}
97
97
guard !keys. isEmpty
98
- else { throw CancellationError ( ) } // TODO: No keys error
98
+ else { throw . keysNotProvided }
99
99
100
100
self . keys = keys
101
101
var deprecatedKeys = deprecatedKeys ?? [ ]
You can’t perform that action at this time.
0 commit comments