This commit is contained in:
1 parent
a9d1159f7e
commit
919dda6a31
4 files changed
+41
-12
No files matched your search
@@ -7,6 +7,8 @@ const { ClouddropLogApi, CloudLogError } = require('./clouddrop-log-api');
|
||||
const MAX_DOCUMENT_BYTES = 700000;
|
||||
const hash = value => createHash('sha256').update(value).digest('hex');
|
||||
const validId = value => typeof value === 'string' && /^[a-zA-Z0-9_-]{1,100}$/.test(value);
|
||||
const blocksRetry = code => ['INVALID_KEY', 'ACCESS_DENIED', 'UNRESTRICTED_KEY_REQUIRED',
|
||||
'LOCAL_STATE_INVALID', 'REMOTE_CONTENT_CHANGED', 'REVISION_REQUIRED'].includes(code);
|
||||
|
||||
class CloudLogSync extends EventEmitter {
|
||||
constructor({ directory, loadSettings, saveSettings, apiFactory, now = Date.now, delayMs = 750 }) {
|
||||
@@ -139,7 +141,7 @@ class CloudLogSync extends EventEmitter {
|
||||
} catch (error) {
|
||||
this.phase = 'error';
|
||||
this.errorCode = this._errorCode(error);
|
||||
this.retryBlocked = ['INVALID_KEY', 'ACCESS_DENIED', 'UNRESTRICTED_KEY_REQUIRED', 'LOCAL_STATE_INVALID'].includes(this.errorCode);
|
||||
this.retryBlocked = blocksRetry(this.errorCode);
|
||||
this.notify();
|
||||
throw new CloudLogError(this.errorCode);
|
||||
} finally {
|
||||
@@ -154,9 +156,9 @@ class CloudLogSync extends EventEmitter {
|
||||
} catch (error) {
|
||||
this.phase = 'error';
|
||||
this.errorCode = this._errorCode(error);
|
||||
this.retryBlocked = ['INVALID_KEY', 'ACCESS_DENIED', 'UNRESTRICTED_KEY_REQUIRED', 'LOCAL_STATE_INVALID'].includes(this.errorCode);
|
||||
this.retryBlocked = blocksRetry(this.errorCode);
|
||||
this.notify();
|
||||
if (!['INVALID_KEY', 'ACCESS_DENIED', 'UNRESTRICTED_KEY_REQUIRED', 'LOCAL_STATE_INVALID'].includes(this.errorCode)) {
|
||||
if (!blocksRetry(this.errorCode)) {
|
||||
this.timer = setTimeout(() => { this.timer = null; void this.start(); }, 30000);
|
||||
this.timer.unref?.();
|
||||
}
|
||||
@@ -271,7 +273,7 @@ class CloudLogSync extends EventEmitter {
|
||||
this.phase = 'error';
|
||||
this.errorCode = this._errorCode(error);
|
||||
this.failures++;
|
||||
this.retryBlocked = ['INVALID_KEY', 'ACCESS_DENIED', 'UNRESTRICTED_KEY_REQUIRED'].includes(this.errorCode);
|
||||
this.retryBlocked = blocksRetry(this.errorCode);
|
||||
} finally {
|
||||
if (this.controller === controller) this.controller = null;
|
||||
this.notify();
|
||||
|
||||
Reference in new issue
Block a user