Skip to content

Fix unhandled promise rejection propagationΒ #85

@pmomot

Description

@pmomot

In executeAsyncOperation the promise rejection scenario is not properly handled. It captures the error, saves it in state, but then it propagates further and causes exceptions in the codebase. I suggest to change the implementation to this

return promise
      .then((result) => {
        if (shouldHandlePromise(promise)) {
          AsyncState.setResult(result);
        }
        normalizedOptions.onSuccess(result, {
          isCurrent: () => CurrentPromise.is(promise),
        });
      })
      .catch((error) => {
        if (shouldHandlePromise(promise)) {
          AsyncState.setError(error);
        }
        normalizedOptions.onError(error, {
          isCurrent: () => CurrentPromise.is(promise),
        });
      });

instead of

promise.then(() => {}, () => {});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions