Last active
May 4, 2018 00:25
-
-
Save bobisme/3665766739f07e0f49759c010b8830fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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