Skip to content

Commit 9978600

Browse files
Retry and finish after requesting new token.
1 parent 1107ded commit 9978600

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

swift-sdk/Internal/RequestProcessorUtil.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ struct RequestProcessorUtil {
1616
reportSuccess(result: result, value: json, successHandler: onSuccess, identifier: identifier)
1717
}
1818
.onError { error in
19-
requestProvider().onSuccess { json in
20-
reportSuccess(result: result, value: json, successHandler: onSuccess, identifier: identifier)
21-
}.onError { error in
22-
if let onFailure = onFailure {
23-
onFailure(error.reason, error.data)
24-
} else {
25-
defaultOnFailure(identifier)(error.reason, error.data)
19+
if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.invalidJwtPayload {
20+
ITBError("invalid JWT token, trying again: \(error.reason ?? "")")
21+
authManager?.requestNewAuthToken(hasFailedPriorAuth: true) { _ in
22+
requestProvider().onSuccess { json in
23+
reportSuccess(result: result, value: json, successHandler: onSuccess, identifier: identifier)
24+
}.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)
31+
}
2632
}
33+
} else if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.badApiKey {
34+
ITBError(error.reason)
2735
result.reject(with: error)
2836
}
37+
2938
}
3039
return result
3140
}

0 commit comments

Comments
 (0)