i399exback/express-examples/express4.js

38 lines
707 B
JavaScript
Raw Permalink Normal View History

2017-04-04 15:57:10 +03:00
'use strict';
const express = require('express');
const app = express();
app.get('/api/p1', p1);
app.get('/api/p2', p2);
app.get('/api/p3', p3);
app.use(errorHandler);
app.listen(3000);
function p1(request, response) {
try {
throw new Error('p1');
} catch (error) {
response.status(500).send(error.toString());
}
}
function p2(request, response) {
try {
throw new Error('p2');
} catch (error) {
response.status(500).send(error.toString());
}
}
function p3(request, response) {
throw new Error('p3');
}
function errorHandler(error, request, response, next) { // there must be 4 arguments
response.status(500).send(error.toString());
}