Skip to content

Commit 2b817ca

Browse files
committed
fix(Account#sync): Always run onSyncFail
and secure it against errors and fix matchAllErrors Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent aa63818 commit 2b817ca

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/lib/Account.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,21 @@ export default class Account {
302302
syncing: false,
303303
scheduled: false,
304304
})
305-
if (matchAllErrors(e, e => e.code !== 27 && (!isTest || e.code !== 26))) {
306-
if (this.server.onSyncFail) {
305+
306+
if (this.server.onSyncFail) {
307+
try {
307308
await this.server.onSyncFail()
309+
} catch (e) {
310+
console.log(e)
311+
Logger.log(e)
312+
Logger.log('Error during onSyncFail hooK: ' + e.message)
308313
}
309314
}
310315
this.syncing = false
311316

312317
// reset cache and mappings after error
313-
// (but not after interruption or NetworkError)
314-
if (matchAllErrors(e, e => e.code !== 27 && e.code !== 17 && (!isTest || e.code !== 26))) {
318+
// (but not after NetworkError)
319+
if (matchAllErrors(e, (e) => e.code !== 17)) {
315320
await this.init()
316321
}
317322
}
@@ -346,5 +351,5 @@ export default class Account {
346351
}
347352

348353
function matchAllErrors(e, fn:(e)=>boolean) {
349-
return fn(e) && e.list && e.list.every(e => matchAllErrors(e, fn))
354+
return fn(e) && (!e.list || e.list.every(e => matchAllErrors(e, fn)))
350355
}

0 commit comments

Comments
 (0)