How do Promise finally t3h work?

I can’t seem to get finally to work; I must be doing something wrong. I had:

->then( stuff => stuff -> Ok -> resolve )
->catch( error => switch and Error(reasons) -> resolve )
->then( result => switch on result and either Js.Exn.raiseError or resolveTheOk )
->finally( this never runs when an error occurs )

I guess the Js.Exn.raiseError stops it from ever running, but… like… why… or rather, what should I be doing instead?

For context, I need to throw an Exception at the end because that’s how AWS Lambdas work. Their contract is “you return data or blow up”, so if I have an error, I need to have a normal exception at the end.

This error example is working for me:

Promise.resolve()
->Promise.then(() => {
  Js.Exn.raiseError("Error")
})
->Promise.finally(() => {
  Js.log("finally")
})
->ignore

And the success case is also working ok:

Promise.resolve()
->Promise.then(() => {
  Promise.resolve()
})
->Promise.finally(() => {
  Js.log("finally")
})
->ignore

Maybe something else you can take a look at is the generated JS code for you Lambda, and see if there might be a hint on why it’s not working?

1 Like

Thanks for verifying, I’ll test locally this morning, appreciate it!