-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_error.js
More file actions
33 lines (28 loc) · 1.03 KB
/
test_error.js
File metadata and controls
33 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require('express');
const globalErrorHandler = require('./apps/backend/src/common/exceptions/GlobalErrorHandlerMiddleware');
const AppError = require('./apps/backend/src/common/exceptions/AppError');
const app = express();
app.get('/test', (req, res, next) => {
next(new Error('This is a test error with a stack trace! /path/to/server'));
});
app.use(globalErrorHandler);
process.env.NODE_ENV = 'production';
const request = require('supertest');
request(app)
.get('/test')
.expect(500)
.end((err, res) => {
if (err) throw err;
console.log("PRODUCTION ERROR RESPONSE:");
console.log(JSON.stringify(res.body, null, 2));
process.env.NODE_ENV = 'development';
request(app)
.get('/test')
.expect(500)
.end((err, res) => {
if (err) throw err;
console.log("\nDEVELOPMENT ERROR RESPONSE:");
console.log(JSON.stringify(res.body, null, 2));
process.exit(0);
});
});