Skip to content

Chained function gets called even if previous operation failed #2

@ideadapt

Description

@ideadapt

sendEIAToProxy is called, even if importKey has failed. (If this is intended behaviour, just ignore this issue :).) Thats because the first error handler returns undefined, which ends up in a resolved promise being returned at the end of line 97, which leads to execution of success handler (sendEIAToProxy).

.then(sendEIAToProxy, (x) => { console.log('Error encrypting IA!', x); });

To mitigate this, you could:

  • use .catch(errorHandler) (not Promise/A+ compliant)
  • .then(null, errorHandler)

at the end of the then chain.

One line of code tells more than any prosa:

Promise.reject("some err").then(null, (...a)=>console.log("errhandler1", ...a)).then((...a)=>console.log("success2", ...a), (...a)=>console.log("errhandler2", ...a))

Its recommended to always have a final error handler at the end. This prevents possibly uncaught promise rejections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions