Skip to content

Commit 257efa9

Browse files
report failure on error
1 parent 7b9892b commit 257efa9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

swift-sdk/Internal/RequestProcessorUtil.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ struct RequestProcessorUtil {
2222
requestProvider().onSuccess { json in
2323
reportSuccess(result: result, value: json, successHandler: onSuccess, identifier: identifier)
2424
}.onError { error in
25-
if let onFailure = onFailure {
26-
onFailure(error.reason, error.data)
27-
} else {
28-
defaultOnFailure(identifier)(error.reason, error.data)
29-
}
30-
result.reject(with: error)
25+
reportFailure(result: result, error: error, failureHandler: onFailure, identifier: identifier)
3126
}
3227
}
3328
} else if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.badApiKey {
3429
ITBError(error.reason)
35-
result.reject(with: error)
30+
reportFailure(result: result, error: error, failureHandler: onFailure, identifier: identifier)
3631
}
37-
32+
3833
}
3934
return result
4035
}
@@ -79,7 +74,20 @@ struct RequestProcessorUtil {
7974
}
8075
result.resolve(with: value)
8176
}
82-
77+
78+
private static func reportFailure(result: Fulfill<SendRequestValue, SendRequestError>,
79+
error: SendRequestError,
80+
failureHandler onFailure: OnFailureHandler?,
81+
identifier: String) {
82+
83+
if let onFailure = onFailure {
84+
onFailure(error.reason, error.data)
85+
} else {
86+
defaultOnFailure(identifier)(error.reason, error.data)
87+
}
88+
result.reject(with: error)
89+
}
90+
8391
private static func defaultOnSuccess(_ identifier: String) -> OnSuccessHandler {
8492
{ data in
8593
if let data = data {

0 commit comments

Comments
 (0)