forked from javascript-tutorial/uk.javascript.info
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promises chaining (javascript-tutorial#259)
- Loading branch information
1 parent
3a1f194
commit a0446e4
Showing
5 changed files
with
103 additions
and
91 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
The short answer is: **no, they are not equal**: | ||
Коротка відповідь: **ні, вони не рівні**: | ||
|
||
The difference is that if an error happens in `f1`, then it is handled by `.catch` here: | ||
Різниця полягає в тому, що якщо помилка відбувається в `f1`, тоді її обробляє `.catch` тут: | ||
|
||
```js run | ||
promise | ||
.then(f1) | ||
.catch(f2); | ||
``` | ||
|
||
...But not here: | ||
...Але не тут: | ||
|
||
```js run | ||
promise | ||
.then(f1, f2); | ||
``` | ||
|
||
That's because an error is passed down the chain, and in the second code piece there's no chain below `f1`. | ||
Це тому, що помилка передається по ланцюжку, а в другому фрагменті коду немає ланцюжка нижче `f1`. | ||
|
||
In other words, `.then` passes results/errors to the next `.then/catch`. So in the first example, there's a `catch` below, and in the second one there isn't, so the error is unhandled. | ||
Іншими словами, `.then` передає результати/помилки наступному `.then/catch`. Отже, у першому прикладі нижче є `catch`, а в другому його немає, тому помилка не оброблена. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.