What’s the difference of the following two code snippets?
first code snippet.
1 | const handler = () => { |
second code snippet.
1 | const handler = () => { |
The first code snippet is xxx.then().catch()
while the second code snippet is xxx.catch().then()
, since promise.catch also return a promise, so handler
in the second code snippet will always be executed. But in the first code snippet, the handler will not be executed.
outputs:
first code snippet.
1 | error in fetchData |
second code snippet.
1 | error in fetchData |