Created
April 26, 2018 11:11
-
-
Save macedigital/090fe2b244728b089ea60fa25154a352 to your computer and use it in GitHub Desktop.
Handle runtime exception with express-js
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
const express = require('express'); | |
const app = express(); | |
const http = require('http'); | |
const server = http.createServer(app); | |
const xmlparser = require('express-xml-bodyparser'); | |
app.use(xmlparser()); | |
app.post('/xml', (req, res, next) => { | |
console.log(req.body); // handle parsed xml | |
res.setHeader('content-type', 'text/plain'); | |
return res.send('yay, xml received!'); | |
}); | |
app.use((err, req, res, next) => { | |
console.error(err); // handle error or just log it | |
return res.send('damn, something went wrong!'); | |
}) | |
server.listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of using ExpressJS error-handling for catching malformed xml; see macedigital/express-xml-bodyparser#21.