Skip to content

Commit db5b86d

Browse files
committed
Further improvement of error handling for LZString
This does some more in depth check on the error message and minimizes the log noise that is caused by LZString. Signed-off-by: Sheogorath <[email protected]>
1 parent 1f85017 commit db5b86d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/history.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ function getHistory (userid, callback) {
4747
}
4848
} catch (err) {
4949
// most error here comes from LZString, ignore
50-
logger.error(err)
50+
if (err.message === 'Cannot read property \'charAt\' of undefined') {
51+
logger.warning('Looks like we can not decode "' + history[i].id + '" with LZString. Can be ignored.')
52+
} else {
53+
logger.error(err)
54+
}
5155
}
5256
}
5357
history = parseHistoryToObject(history)

lib/models/note.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
227227
var id = LZString.decompressFromBase64(noteId)
228228
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
229229
} catch (err) {
230-
logger.error(err)
230+
if (err.message === 'Cannot read property \'charAt\' of undefined') {
231+
logger.warning('Looks like we can not decode "' + noteId + '" with LZString. Can be ignored.')
232+
} else {
233+
logger.error(err)
234+
}
231235
return _callback(null, null)
232236
}
233237
},

0 commit comments

Comments
 (0)