/** * Throw an error without stopping nodejs program * * @param {String} message - message to debug * @param {Error} error - unexpected error, if any, that returned from the function * * @return false **/ var throwError = function (message, error) { debugError(message); if (error) debugError(error); return false; }
app.use(function(err, req, res, next) { err.status = err.status || 500; if (err.status != 404 && err.status != 401) { debugError('[ERROR]') debugError(err) } res.status(err.status); res.render('error', { message: err.message, error: err, notFound: err.status == 404, serverError: err.status == 500, unauthorized: err.status == 403, forumPath: forumPath }); });
/** * event fires if TuyaDevice sends data * @see TuyAPI (https://github.com/codetheweb/tuyapi) */ TuyaDevice.onAll('data', function (data) { try { if (typeof data.dps != "undefined") { debugTuya('Data from device ' + this.type + ' :', data); var status = data.dps['1']; if (typeof status != "undefined") { publishStatus(this, bmap(status)); } publishDPS(this, data.dps); } } catch (e) { debugError(e); } });
debugError('DYNAMO PUT ITEM: ', err); return Promise.reject(err); }) debugError('DYNAMO GET ITEM: ', err); const errJson = { code: err.code,
debugError('UPLOAD PHOTO REQUEST: ', err); return redirect(JSON.stringify({ name: err.name,
debugError('GET PHOTOS REQUEST: ', err); return renderHomepage({ err }); bodyJson = JSON.parse(body); } catch (e) { debugError('GET PHOTOS REQUEST BODY PARSING: ', e); return renderHomepage({ err: JSON.stringify({ debugError('INVALID PHOTOS REQUEST STATUS: ', { statusCode: response.statusCode, body
debugError(err); }); } catch (e) { debugError(e);
debugError('Data from device not encrypted:', data.replace(/[^a-zA-Z0-9 ]/g, "")); } else { debug('Data from device:', data); debugError(err); device.triggerAll('error', err); return reject({
// production error handler // no stacktraces leaked to user app.use(function(err, req, res, next) { if (!err.status) err.status = 500; if (err.status != 404 && err.status != 401) { debugError('[ERROR]') debugError(err) } res.status(err.status || 500); res.render('error', { message: err.message, notFound: err.status == 404, serverError: err.status == 500, unauthorized: err.status == 403, error: { status: err.status }, forumPath: forumPath }); });