Created
December 9, 2016 09:56
-
-
Save kketch/b7a84bb830bd071e672fbe1c52cfd071 to your computer and use it in GitHub Desktop.
Throwing an error with fortune test
This file contains 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
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