fix: Remove invalid account cache file when load error

This commit is contained in:
AkiraFukushima 2019-08-29 22:45:18 +09:00
parent 1229399bc7
commit 21f2fadf85
1 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import { isEmpty } from 'lodash'
import Datastore from 'nedb'
import fs from 'fs'
import { CachedAccount } from '~/src/types/cachedAccount'
export default class AccountCache {
@ -8,7 +9,16 @@ export default class AccountCache {
constructor(path: string) {
this.db = new Datastore({
filename: path,
autoload: true
autoload: true,
onload: (err: Error) => {
if (err) {
fs.unlink(path, err => {
if (err) {
console.error(err)
}
})
}
}
})
}