Skip to content

Commit 4cc4c34

Browse files
committed
✨ Add printFullStack option
1 parent 89d8aab commit 4cc4c34

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

leanengine.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ declare module 'leanengine' {
3030
}
3131

3232
interface MiddlewareOptions {
33-
timeout?: string
33+
timeout?: string,
34+
printFullStack?: boolean
3435
}
3536

3637
export function init(options: InitializeOptions): void;

lib/leanengine.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function createCloudFunctionRouter(options) {
104104
cloudFunctions.use(function(req, res, next) {
105105
promiseTry( () => {
106106
if (req.url === '/') {
107-
throw new Cloud.Error(`No function name or class name: ${req.originalUrl}`, {status: 404, printToLog: true});
107+
throw new Cloud.Error(`No function name or class name: ${req.originalUrl}`, {status: 404, printToLog: true, printFullStack: false});
108108
}
109109

110110
const [__, functionOrClass, hookName] = req.url.split('/');
@@ -132,7 +132,11 @@ function createCloudFunctionRouter(options) {
132132
}
133133

134134
if (statusCode === 500 || err.printToLog) {
135-
console.warn(`LeanEngine: ${req.url}: ${statusCode}: ${err.stack || err.message}`);
135+
if (options.printFullStack !== false && err.printFullStack !== false) {
136+
console.warn(`LeanEngine: ${req.url}: ${statusCode}: ${err.stack || err.message}`);
137+
} else {
138+
console.warn(`LeanEngine: ${req.url}: ${statusCode}: ${err.name}: ${err.message}`);
139+
}
136140
}
137141

138142
if (!res.headersSent) {
@@ -163,7 +167,7 @@ function callCloudFunction(req, funcName) {
163167
const cloudFunction = Cloud.functions[funcName];
164168

165169
if (!cloudFunction) {
166-
throw new Cloud.Error(`No such cloud function '${funcName}'`, {status: 404, printToLog: true});
170+
throw new Cloud.Error(`No such cloud function '${funcName}'`, {status: 404, printToLog: true, printFullStack: false});
167171
}
168172

169173
if (_.contains(REALTIME_HOOKS, funcName)) {
@@ -214,7 +218,7 @@ function callClassHook(req, className, hookName) {
214218
checkHookKey(req);
215219

216220
if (!hookFunction) {
217-
throw new Cloud.Error(`No ${hookName} hook of '${className}'`, {status: 404, printToLog: true});
221+
throw new Cloud.Error(`No ${hookName} hook of '${className}'`, {status: 404, printToLog: true, printFullStack: false});
218222
}
219223

220224
const object = decodeParams(_.extend({}, req.body.object, {
@@ -264,7 +268,7 @@ function callUserHook(req, hookName, verifType) {
264268
checkHookKey(req);
265269

266270
if (!userHookFunction) {
267-
throw new Cloud.Error(`No such hook: ${hookName}`, {status: 404, printToLog: true});
271+
throw new Cloud.Error(`No such hook: ${hookName}`, {status: 404, printToLog: true, printFullStack: false});
268272
}
269273

270274
const user = decodeUser(req.body.object);
@@ -337,7 +341,7 @@ function responseError(res, err) {
337341
function checkHookKey(req) {
338342
if (req.headers['x-lc-hook-key'] !== AV.hookKey) {
339343
throw new Cloud.Error(`Hook key check failed, request from ${utils.getRemoteAddress(req)}`, {
340-
status: 401, code: 401, printToLog: true
344+
status: 401, code: 401, printToLog: true, printFullStack: false
341345
});
342346
}
343347
}

0 commit comments

Comments
 (0)