2016-05-03 22:50:21 +00:00
|
|
|
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2015-07-05 17:20:34 +00:00
|
|
|
var loopback = require('../');
|
|
|
|
var app;
|
|
|
|
var assert = require('assert');
|
|
|
|
var request = require('supertest');
|
|
|
|
|
|
|
|
describe('loopback.errorHandler(options)', function() {
|
|
|
|
it('should return default middleware when options object is not present', function(done) {
|
|
|
|
//arrange
|
|
|
|
var app = loopback();
|
|
|
|
app.use(loopback.urlNotFound());
|
|
|
|
app.use(loopback.errorHandler({ log: false }));
|
|
|
|
|
|
|
|
//act/assert
|
|
|
|
request(app)
|
|
|
|
.get('/url-does-not-exist')
|
|
|
|
.end(function(err, res) {
|
|
|
|
assert.ok(res.error.text.match(/<ul id="stacktrace"><li> at raiseUrlNotFoundError/));
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2015-07-05 17:20:34 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete stack when options.includeStack is false', function(done) {
|
|
|
|
//arrange
|
|
|
|
var app = loopback();
|
|
|
|
app.use(loopback.urlNotFound());
|
|
|
|
app.use(loopback.errorHandler({ includeStack: false, log: false }));
|
|
|
|
|
|
|
|
//act/assert
|
|
|
|
request(app)
|
|
|
|
.get('/url-does-not-exist')
|
|
|
|
.end(function(err, res) {
|
|
|
|
assert.ok(res.error.text.match(/<ul id="stacktrace"><\/ul>/));
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2015-07-05 17:20:34 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pass options on to error handler module', function(done) {
|
|
|
|
//arrange
|
|
|
|
var app = loopback();
|
|
|
|
app.use(loopback.urlNotFound());
|
|
|
|
|
2016-02-04 15:52:50 +00:00
|
|
|
var errorLogged;
|
|
|
|
app.use(loopback.errorHandler({
|
|
|
|
includeStack: false,
|
|
|
|
log: function customLogger(err, str, req) {
|
|
|
|
errorLogged = err;
|
2016-04-01 09:14:26 +00:00
|
|
|
},
|
2016-02-04 15:52:50 +00:00
|
|
|
}));
|
2015-07-05 17:20:34 +00:00
|
|
|
|
2016-02-04 15:52:50 +00:00
|
|
|
//act
|
|
|
|
request(app).get('/url-does-not-exist').end(function(err) {
|
|
|
|
if (err) return done(err);
|
|
|
|
//assert
|
|
|
|
expect(errorLogged)
|
|
|
|
.to.have.property('message', 'Cannot GET /url-does-not-exist');
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2015-07-05 17:20:34 +00:00
|
|
|
done();
|
2016-02-04 15:52:50 +00:00
|
|
|
});
|
2015-07-05 17:20:34 +00:00
|
|
|
});
|
|
|
|
});
|