Skip to content

Commit 8568276

Browse files
committed
Merge pull request #25 from digitalsadhu/next
Added debug and enable option
2 parents 9936b6e + 8c415c4 commit 8568276

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = function (app, options) {
2+
var debug = options.debug;
23
//turn off strong remoting rest error handler so that we can catch all errors
34
//here
45
//TODO: need to wait until PR is accepted
@@ -15,7 +16,7 @@ module.exports = function (app, options) {
1516
function JSONAPIErrorHandler (err, req, res, next) {
1617
res.set('Content-Type', 'application/vnd.api+json');
1718
var status = err.status || err.statusCode || 500;
18-
19+
debug(err);
1920
res.status(status).send({
2021
errors: [{
2122
status: status,

lib/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var _ = require('lodash');
34
var headers = require('./headers');
45
var patch = require('./patch');
56
var serialize = require('./serialize');
@@ -8,12 +9,22 @@ var removeRemoteMethods = require('./removeRemoteMethods');
89
var create = require('./create');
910
var update = require('./update');
1011
var errors = require('./errors');
12+
var debug = require('debug')('loopback-component-jsonapi');
1113

1214
module.exports = function (app, options) {
13-
if (!options || !options.restApiRoot) {
14-
options = { restApiRoot: '/api' };
15-
}
15+
var defaultOptions = {
16+
restApiRoot: '/api',
17+
enable: true
18+
};
19+
options = options || {};
20+
options = _.defaults(options, defaultOptions);
1621

22+
if (!options.enable) {
23+
debug('Disabled');
24+
return;
25+
}
26+
debug('Started');
27+
options.debug = debug;
1728
headers(app, options);
1829
removeRemoteMethods(app, options);
1930
patch(app, options);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
"homepage": "https://github.com/digitalsadhu/loopback-component-jsonapi#readme",
2727
"dependencies": {
2828
"body-parser": "^1.14.1",
29+
"debug": "^2.2.0",
2930
"inflection": "^1.7.2",
30-
"jsonapi-serializer": "^2.0.2"
31+
"jsonapi-serializer": "^2.0.2",
32+
"lodash": "^3.10.1"
3133
},
3234
"devDependencies": {
3335
"babel-eslint": "^4.1.3",

0 commit comments

Comments
 (0)