View fcc-count.js
JSON.stringify(Array.from(document.querySelectorAll('#accordion > *')).map((node, i, items) => {
if (node.nodeName !== 'H2') return false
const next = items[i + 1]
return {
title: node.querySelector('a').innerText.trim(),
items: Array.from(next.querySelectorAll('#nested > *')).map((node, i, items) => {
if (node.nodeName !== 'H3') return false
const next = items[i + 1]
return {
View error-translation-gg.js
async function someHellComputation(initialData) {
const a = await fnA(initialData).catch(() => { throw 'errored on A' })
const b = await fnB(a).catch(() => { throw 'errored on B' })
return await fnC(b).catch(() => { throw 'errored on C' })
}
someHellComputation(10)
.then(console.log)
.catch(console.error)
View error-translation-for-the-win.js
const databaseGetUser = id =>
id === 'not-exists'
? Promise.reject('some weird database error')
: Promise.resolve({id, username: 'username'})
const databaseGetPosts = user =>
user.id === 'fail-to-get-posts'
? Promise.reject('some weird database error for posts')
: Promise.resolve([{title: 'A'}, {title: 'B'}])
View nested-promise-translation-error-fail.js
const databaseGetUser = id =>
id === 'not-exists'
? Promise.reject('some weird database error')
: Promise.resolve({id, username: 'username'})
const databaseGetPosts = user =>
user.id === 'fail-to-get-posts'
? Promise.reject('some weird database error')
: Promise.resolve([{title: 'A'}, {title: 'B'}])
View flat-promise.js
const databaseGetUser = id =>
id === 'not-exists'
? Promise.reject('some weird database error')
: Promise.resolve({id, username: 'username'})
function getUser(id) {
return databaseGetUser(id)
.catch(err => { throw 'user doesn\'t exists' })
}
View translating-promise-errors.js
Promise.reject('some error')
.catch(err => { throw 'earth is not flat' }) // runs
.catch(err => console.log(err)) // logs 'earth is not flat'
View propagating-promise-errors.js
Promise.reject('some error')
.catch(err => { throw err }) // runs
.catch(err => console.log(2)) // runs
View promise-catch-doesnt-propagate.js
Promise.reject('some error')
.catch(err => console.log(1)) // runs
.catch(err => console.log(2)) // never runs
View promise-part2.js
function someHellComputation(initialData) {
return fnA(initialData)
.then(fnB)
.then(fnC)
}
someHellComputation(10)
.then(console.log)
.catch(err => {
// where does err come from: fnA, fnB, fnC?
View promise.js
function someHellComputation(initialData) {
return fnA(initialData)
.then(fnB)
.then(fnC)
}
someHellComputation(10)
.then(console.log)
.catch(console.error)