Skip to content

Instantly share code, notes, and snippets.

@macedigital

macedigital/index.js

Created Apr 26, 2018
Embed
What would you like to do?
Handle runtime exception with express-js
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);
@macedigital

This comment has been minimized.

Copy link
Owner Author

@macedigital macedigital commented Apr 26, 2018

Example of using ExpressJS error-handling for catching malformed xml; see macedigital/express-xml-bodyparser#21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment