Hello there! I have a question regarding custom er...
# multiplatform
v
Hello there! I have a question regarding custom errors in KMP. I have this code on kotlin side:
Copy code
class BadRequest(override val message: String?) : Throwable()

@Throws(BadRequest::class, Throwable::class)
suspend fun login(email: String, password: String): Boolean {
    ...
    throw BadRequest("some message")
}
On iOS side I use it like this:
Copy code
do {
    let loggedSuccessfully = try await api.login(email: email, password: password)
} catch {
    print(error is BadRequest)
}
So on iOS it is always prints
false
. In debug I see that
error
is an
NSError
and cannot be casted to custom
BadRequest
. Is there any way to fix?
Looks like this solves the problem
Copy code
(error as NSError).kotlinException {
    print(error is BadRequest)
}
// true