Hello, on a iOS app using a KMP module, I have a c...
# ktor
r
Hello, on a iOS app using a KMP module, I have a crash
DarwinHttpRequestException
, with the error
Kubernetes Ingress Controller Fake Certificate i: Kubernetes Ingress Controller Fake Certificate
I dunno where to catch this error ?
a
Can you share the full stack trace?
r
Copy code
REQUEST https:/xxxx/configurations failed with exception: io.ktor.client.engine.darwin.DarwinHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1200 "Une erreur SSL s’est produite et il est impossible d’établir une connexion sécurisée avec le serveur." UserInfo={NSLocalizedRecoverySuggestion=Voulez-vous tout de même vous connecter à ce serveur ?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x1138c3c00) s: Kubernetes Ingress Controller Fake Certificate i: Kubernetes Ingress Controller Fake Certificate>"
), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=https:/xxxx/configurations, NSErrorFailingURLStringKey=https:/xxxx/configurations, NSUnderlyingError=0x600000dcc5a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x60000350aec0>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x1138c3c00) s: Kubernetes Ingress Controller Fake Certificate i: Kubernetes Ingress Controller Fake Certificate>"
)}}, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <48BAF2A6-1A6B-4AAD-B45A-7E936A3D3F88>.<1>"
), _kCFStreamErrorCodeKey=-9802, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <48BAF2A6-1A6B-4AAD-B45A-7E936A3D3F88>.<1>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x60000350aec0>, NSLocalizedDescription=Une erreur SSL s’est produite et il est impossible d’établir une connexion sécurisée avec le serveur.}
Exception doesn't match @Throws-specified class list and thus isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: io.ktor.client.engine.darwin.DarwinHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1200 "Une erreur SSL s’est produite et il est impossible d’établir une connexion sécurisée avec le serveur." UserInfo={NSLocalizedRecoverySuggestion=Voulez-vous tout de même vous connecter à ce serveur ?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x1138c3c00) s: Kubernetes Ingress Controller Fake Certificate i: Kubernetes Ingress Controller Fake Certificate>"
), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=https:/xxxx/configurations, NSErrorFailingURLStringKey=https:/xxxx/configurations, NSUnderlyingError=0x600000dcc5a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x60000350aec0>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x1138c3c00) s: Kubernetes Ingress Controller Fake Certificate i: Kubernetes Ingress Controller Fake Certificate>"
)}}, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <48BAF2A6-1A6B-4AAD-B45A-7E936A3D3F88>.<1>"
), _kCFStreamErrorCodeKey=-9802, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <48BAF2A6-1A6B-4AAD-B45A-7E936A3D3F88>.<1>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x60000350aec0>, NSLocalizedDescription=Une erreur SSL s’est produite et il est impossible d’établir une connexion sécurisée avec le serveur.}
Sorry, there is bit of french
a
Have you tried catching it by wrapping the code where the request is made?
r
Yes it's in a try/catch module side
a
I am able to catch the
DarwinHttpRequestException
with the following code:
Copy code
try {
    client.get("<https://untrusted-root.badssl.com/>")
} catch (e: DarwinHttpRequestException) {
    println(e)
}
r
Weird I have this
Copy code
suspend inline fun <T : Any> customRunCatching(block: () -> T): CustomResult<T> {
    return try {
        CustomResult.success(block())
    } catch (e: Exception) {
        e.toCustomResult()
    }
}

customRunCatching { client.get("....") }
You tested on iOS side or only kotlin ?
a
I've tested on the macosArm64 target, which has the same underlying functionality as iOS.
May the exception from
CustomResult
to be thrown somewhere later?
r
Of what I see, it's not
Weird because for 4XX errorCode request it's working, but not this
Maybe it's due to
expectSuccess = true
, and it throw 2 times, first is catch but not the second?
a
You can catch
Throwable
to make sure the exception is definitely caught.
r
Thanks will try