Skip to content

Instantly share code, notes, and snippets.

@despairblue
Created May 26, 2016 15:48
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 despairblue/ee45362d86a7106997111e1e6806354a to your computer and use it in GitHub Desktop.
Save despairblue/ee45362d86a7106997111e1e6806354a to your computer and use it in GitHub Desktop.
'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