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 <sheogorath@shivering-isles.com>
This commit is contained in:
Sheogorath 2018-07-27 13:56:07 +02:00
parent 1f85017625
commit db5b86df4c
No known key found for this signature in database
GPG key ID: 1F05CC3635CDDFFD
2 changed files with 10 additions and 2 deletions

View file

@ -47,9 +47,13 @@ function getHistory (userid, callback) {
} }
} catch (err) { } catch (err) {
// most error here comes from LZString, ignore // most error here comes from LZString, ignore
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) logger.error(err)
} }
} }
}
history = parseHistoryToObject(history) history = parseHistoryToObject(history)
} }
if (config.debug) { if (config.debug) {

View file

@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
var id = LZString.decompressFromBase64(noteId) var id = LZString.decompressFromBase64(noteId)
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) } if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
} catch (err) { } catch (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) logger.error(err)
}
return _callback(null, null) return _callback(null, null)
} }
}, },