Ah, a third option.
The underlying problem is that, within a Promise.make call, reject needs to be called on items of the same type. We can’t cast exn to JsError.t, but we can convert JsError.t to JSExn.t:
k->Context.onError((error: JsError.t) => {
k->Context.quit
reject(JsError.toJsExn(error))
})
k->Context.onLoad(() => {
testFn(k)
->thenResolve(resolve)
->catchJSError(err => reject(JsError.toJsExn(err)))
->finally(
() => {
k->Context.quit
},
)
->ignore
})
Wrapping the errors into exceptions like this would then let us mix in exn via JsExn.fromException