Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
The short answer is: **no, they are not the equal**:
La respuesta corta es: **no, no son iguales**:

The difference is that if an error happens in `f1`, then it is handled by `.catch` here:
La diferencia es que si ocurre un error en `f1`, entonces aqui es manejado por `.catch`:

```js run
promise
.then(f1)
.catch(f2);
```

...But not here:
...Pero no aquí:

```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`.
Esto se debe a que se pasa un error por la cadena y en la segunda pieza del código no hay una cadena debajo de `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.
En otras palabras, `.then` pasa los resultados/errores al siguiente `.then/catch`. Entonces, en el primer ejemplo, hay un `catch` debajo, y en el segundo no lo hay, por lo que el error no se maneja.
4 changes: 2 additions & 2 deletions 1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Promise: then versus catch
# Promesa: then versus catch

Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions?
¿Son iguales estos fragmentos de código? En otras palabras, ¿se comportan de la misma manera en cualquier circunstancia, para cualquier función de controlador?

```js
promise.then(f1).catch(f2);
Expand Down
194 changes: 87 additions & 107 deletions 1-js/11-async/03-promise-chaining/article.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 1-js/11-async/03-promise-chaining/getMessage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function getMessage() {
return "Hello, world!";
return "Hola, mundo!";
}
21 changes: 1 addition & 20 deletions 1-js/11-async/03-promise-chaining/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,11 @@
script.src = src;

script.onload = () => resolve(script);
script.onerror = () => reject(new Error("Script load error: " + src));
script.onerror = () => reject(new Error("Error de carga de script: " + src));

document.head.append(script);
});
}

class HttpError extends Error {
constructor(response) {
super(`${response.status} for ${response.url}`);
this.name = 'HttpError';
this.response = response;
}
}

function loadJson(url) {
return fetch(url)
.then(response => {
if (response.status == 200) {
return response.json();
} else {
throw new HttpError(response);
}
})
}
</script>

<style>
Expand Down
59 changes: 1 addition & 58 deletions 1-js/11-async/03-promise-chaining/promise-handler-variants.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 1 addition & 38 deletions 1-js/11-async/03-promise-chaining/promise-then-chain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 1 addition & 32 deletions 1-js/11-async/03-promise-chaining/promise-then-many.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.