Skip to content

Instantly share code, notes, and snippets.

@bobisme
Last active May 4, 2018 00:25
Show Gist options
  • Save bobisme/3665766739f07e0f49759c010b8830fc to your computer and use it in GitHub Desktop.
Save bobisme/3665766739f07e0f49759c010b8830fc to your computer and use it in GitHub Desktop.
request = require('superagent')
request.get('http://httpbin.org/status/200')
.then(req => console.log(`got status: ${req.status}`))
.catch(err => console.error(err))
// got status: 200
request.get('http://httpbin.org/status/500')
.then(req => console.log(`got status: ${req.status}`))
.catch(req => console.log(`error with status: ${req.status}`))
// error with status: 500
request.get('http://httpbin.org/status/422')
.then(req => console.log(`got status: ${req.status}`))
.catch(req => console.log(`error with status: ${req.status}`))
// error with status: 422
// fetch.get('http://httpbin.org/status/422')
// .then(req => console.log(`got status: ${req.status}`))
// .catch(req => console.log(`error with status: ${req.status}`))
// got status: 422
new Promise((resolve, reject) => {
throw new Error('poop')
}).then(() => console.log('happy'))
.catch(err => console.error(`sad: ${err.message}`))
// sad: poop
new Promise((resolve, reject) => {
reject('poop')
}).then(() => console.log('happy'))
.catch(err => console.error(`sad: ${err}`))
// sad: poop
new Promise((resolve, reject) => {
throw new Error('poop')
}).then(() => console.log('happy'))
// UnhandledRejectionException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment