From 8695a1c0497c57cb0747d05d953cbb00f11f85c8 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 31 Jul 2020 01:13:51 +0200 Subject: [PATCH] Fixed mapping response that isSuccessful gets set to false if response code is not a 2xx --- .../BankingiOSApp/fints4k/UrlSessionWebClient.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/fints4k/UrlSessionWebClient.swift b/ui/BankingiOSApp/BankingiOSApp/fints4k/UrlSessionWebClient.swift index 1ed84201..22f17d95 100644 --- a/ui/BankingiOSApp/BankingiOSApp/fints4k/UrlSessionWebClient.swift +++ b/ui/BankingiOSApp/BankingiOSApp/fints4k/UrlSessionWebClient.swift @@ -88,16 +88,22 @@ class UrlSessionWebClient : Fints4kIWebClient { } private func mapResponse(_ data: Data?, _ response: URLResponse?, _ error: Error?) -> Fints4kWebClientResponse { + let mappedError = error == nil ? nil : KotlinException(message: error?.localizedDescription) + if let httpResponse = response as? HTTPURLResponse { + let statusCode = Int32(httpResponse.statusCode) + let isSuccessful = mappedError == nil + && statusCode >= 200 && statusCode <= 299 + if let data = data { - return Fints4kWebClientResponse(successful: true, responseCode: Int32(httpResponse.statusCode), error: nil, body: String(data: data, encoding: .ascii)) + return Fints4kWebClientResponse(successful: isSuccessful, responseCode: statusCode, error: mappedError, body: String(data: data, encoding: .ascii)) } else { - return Fints4kWebClientResponse(successful: true, responseCode: Int32(httpResponse.statusCode), error: nil, body: nil) + return Fints4kWebClientResponse(successful: isSuccessful, responseCode: statusCode, error: mappedError, body: nil) } } else { - return Fints4kWebClientResponse(successful: false, responseCode: -1, error: KotlinException(message: error?.localizedDescription), body: nil) + return Fints4kWebClientResponse(successful: false, responseCode: -1, error: mappedError, body: nil) } }