Skip to content

Commit 46ec495

Browse files
authored
Merge pull request #792 from Iterable/MOB-9192-JWT-error-mapping
Mob 9192 JWT error Mapping
2 parents 6a621f6 + 73c12f6 commit 46ec495

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

swift-sdk/Internal/NetworkHelper.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ struct NetworkHelper {
156156
if httpStatusCode >= 500 {
157157
return .failure(NetworkError(reason: "Internal Server Error", data: data, httpStatusCode: httpStatusCode))
158158
} else if httpStatusCode >= 400 {
159+
160+
if let data = data,
161+
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
162+
let msg = json["msg"] as? String {
163+
return .failure(NetworkError(reason: msg, data: data, httpStatusCode: httpStatusCode))
164+
}
159165
return .failure(NetworkError(reason: "Invalid Request", data: data, httpStatusCode: httpStatusCode))
160166
} else if httpStatusCode == 200 {
161167
if let data = data, data.count > 0 {

swift-sdk/Internal/RequestSender.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct SendRequestError: Error {
5757
iterableCode = jsonDict[JsonKey.Response.iterableCode] as? String
5858
}
5959

60-
return SendRequestError(reason: "Invalid API Key",
60+
return SendRequestError(reason: networkError.reason,
6161
data: networkError.data,
6262
httpStatusCode: httpStatusCode,
6363
iterableCode: iterableCode,

tests/unit-tests/IterableAPIResponseTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class IterableAPIResponseTests: XCTestCase {
156156
createApiClient(networkSession: MockNetworkSession(statusCode: 401))
157157
.send(iterableRequest: iterableRequest).onError { sendError in
158158
xpectation.fulfill()
159-
XCTAssert(sendError.reason!.lowercased().contains("invalid api key"))
159+
XCTAssert(sendError.reason!.lowercased().contains("invalid request"))
160160
}
161161

162162
wait(for: [xpectation], timeout: testExpectationTimeout)

0 commit comments

Comments
 (0)