Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict'
const express = require('express')
const axios = require('axios')
const format = require('util').format
const app = express()
app.use(function (request, response, next) {
console.log('Got request')
// any of these
// throw undefined
// next()
// next(undefined)
// throw null
// throw ''
// throw false
// throw 0
// next(null)
// next('')
// next(false)
// next(0)
})
app.use(function (error, request, response, next) {
console.log('I want to handle the error but get never called.')
console.trace(error)
response.json("Don't Panic!")
})
app.listen(3001, function () {
console.log('Listening ...')
axios('http://localhost:3001')
.then(function (response) {
console.log(`Got response ${format(response)}`)
})
.catch(function (error) {
console.trace(`Uh Oh: ${format(error)}`)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment