Skip to content

Commit

Permalink
Further improvement of error handling for LZString
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
SISheogorath committed Jul 27, 2018
1 parent 1f85017 commit db5b86d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function getHistory (userid, callback) {
}
} catch (err) {
// most error here comes from LZString, ignore
logger.error(err)
if (err.message === 'Cannot read property \'charAt\' of undefined') {
logger.warning('Looks like we can not decode "' + history[i].id + '" with LZString. Can be ignored.')
} else {
logger.error(err)
}
}
}
history = parseHistoryToObject(history)
Expand Down
6 changes: 5 additions & 1 deletion lib/models/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
var id = LZString.decompressFromBase64(noteId)
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
} catch (err) {
logger.error(err)
if (err.message === 'Cannot read property \'charAt\' of undefined') {
logger.warning('Looks like we can not decode "' + noteId + '" with LZString. Can be ignored.')
} else {
logger.error(err)
}
return _callback(null, null)
}
},
Expand Down

0 comments on commit db5b86d

Please sign in to comment.