``` fun <V> Promise<V, Exception>.catc...
# kovenant
m
Copy code
fun <V> Promise<V, Exception>.catch(context: Context = Kovenant.context, map: (Exception) -> V): Promise<V, Exception> {
    if (isDone()) {
        if (isSuccess()) return this.withContext(context)
        if (isFailure()) return task(context) { map(getError()) }
    }

    val deferred = deferred<V, Exception>(context)
    success {
        deferred.resolve(it)
    }
    fail {
        context.workerContext.offer {
            try {
                deferred.resolve(map(it))
            } catch (e:Exception) {
                deferred.reject(e)
            }
        }
    }

    return deferred.promise
}