Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active July 1, 2019 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/e2415299660eb58ba134a8db78692cd6 to your computer and use it in GitHub Desktop.
Save kunigami/e2415299660eb58ba134a8db78692cd6 to your computer and use it in GitHub Desktop.
function f() {
return Math.random() > 0.5 ?
Promise.resolve(10) :
Promise.reject(new Error('code x'));
}
function g() {
return f().then(r => {
return r + 1;
}).catch(e => {
return new Error('error:' + e.message);
});
}
g()
.then(r => console.log(r))
.catch(e => console.error(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment