Skip to content

Commit 8101999

Browse files
committed
hm
1 parent bb277a3 commit 8101999

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/SwiftAPIClient/Modifiers/ErrorHandler.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import Foundation
33
public extension APIClient {
44

55
/// Sets the error handler.
6-
func errorHandler(_ handler: @escaping (Error, APIClient.Configs, APIErrorContext) throws -> Void) -> APIClient {
6+
func errorHandler(
7+
insertingBeforeExisting: Bool = false,
8+
_ handler: @escaping (Error, APIClient.Configs, APIErrorContext) throws -> Void
9+
) -> APIClient {
710
configs { configs in
811
let current = configs.errorHandler
912
configs.errorHandler = { failure, configs, context in
13+
let (first, second) = insertingBeforeExisting ? (handler, current) : (current, handler)
1014
do {
11-
try current(failure, configs, context)
15+
try first(failure, configs, context)
1216
} catch {
13-
try handler(error, configs, context)
17+
try second(error, configs, context)
1418
throw error
1519
}
1620
}

0 commit comments

Comments
 (0)