diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-03-13 23:51:25 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-03-13 23:51:25 +0300 |
commit | a566460a56afef809d8d21b24bc4e12f7dd1289a (patch) | |
tree | d25517f11519fc2f49252424f78c044523e079bd | |
parent | 9eeb7c8bf546a9d162c29d3100a37354d376abc9 (diff) |
cookies: catch json.parse errors
-rw-r--r-- | cookies-storage.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cookies-storage.js b/cookies-storage.js index 25d7f1c..8c9231b 100644 --- a/cookies-storage.js +++ b/cookies-storage.js @@ -35,7 +35,13 @@ module.exports = { async get() { if (!(await exists(storageFileName))) return [] - return JSON.parse(await fs.readFile(storageFileName, 'utf-8')) + + try { + return JSON.parse(await fs.readFile(storageFileName, 'utf-8')) + } catch (e) { + console.error(e) + return [] + } }, setFileName(name) { |