Skip to content

Then catch

Description

Just quick note, order are important.

This will work, avoiding closing the modal if the mutation fails.

ts
const _o$ = this._creatorSrv.mutate({input: {
    ...data,
  }})
  return await firstValueFrom(_o$)
  .then((result) => {
    this.modalState?.next(true);
  })
  .catch((e) => {
    console.error(e);
    console.error('Failed to do something.');
  });
}

This will not work, and the modal will close if the mutation fails.

ts
const _o$ = this._creatorSrv.mutate({input: {
    ...data,
  }})
  return await firstValueFrom(_o$)
   .catch((e) => {
    console.error(e);
    console.error('Failed to do something.');
  })
  .then((result) => {
    this.modalState?.next(true);
  });
}