Skip to content

Instantly share code, notes, and snippets.

@kketch
Created December 9, 2016 09:56
Show Gist options
  • Save kketch/b7a84bb830bd071e672fbe1c52cfd071 to your computer and use it in GitHub Desktop.
Save kketch/b7a84bb830bd071e672fbe1c52cfd071 to your computer and use it in GitHub Desktop.
Throwing an error with fortune test
const fortune = require('fortune')
const fortuneHTTP = require('fortune-http')
const { errors: { BadRequestError } } = fortune
function input(context, record) {
switch (context.request.method) {
case 'create':
return record
case 'update':
throw new BadRequestError('Invalid status')
default:
return null
}
}
const store = fortune({
customer: {
name: { type: String }
}
}, {
hooks: {
customer: [input]
}
})
const api = fortuneHTTP(store)
const http = require('http')
const app = http.createServer((request, response) => {
api(request, response).catch(error => {
console.error(error.stack)
})
}).listen(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment