chore: let user know about 429 status (#2747)
This commit is contained in:
@@ -56,4 +56,5 @@ export enum ApplicationEvent {
|
||||
/** Called when the app first launches and after first sync request made after sign in */
|
||||
CompletedInitialSync = 'Application:CompletedInitialSync',
|
||||
DidPurchaseSubscription = 'Application:DidPurchaseSubscription',
|
||||
SyncTooManyRequests = 'Application:SyncTooManyRequests',
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export enum SyncEvent {
|
||||
ReceivedSharedVaultInvites = 'received-shared-vault-invites',
|
||||
ReceivedNotifications = 'received-user-events',
|
||||
ReceivedAsymmetricMessages = 'received-asymmetric-messages',
|
||||
TooManyRequests = 'too-many-requests',
|
||||
}
|
||||
|
||||
export type SyncEventReceivedRemoteSharedVaultsData = SharedVaultServerHash[]
|
||||
|
||||
@@ -16,6 +16,7 @@ const map: Record<string, ApplicationEvent> = {
|
||||
[SyncEvent.DatabaseReadError]: ApplicationEvent.LocalDatabaseReadError,
|
||||
[SyncEvent.DatabaseWriteError]: ApplicationEvent.LocalDatabaseWriteError,
|
||||
[SyncEvent.DownloadFirstSyncCompleted]: ApplicationEvent.CompletedInitialSync,
|
||||
[SyncEvent.TooManyRequests]: ApplicationEvent.SyncTooManyRequests,
|
||||
}
|
||||
|
||||
export function applicationEventForSyncEvent(syncEvent: SyncEvent): ApplicationEvent | undefined {
|
||||
|
||||
@@ -100,6 +100,7 @@ import { ContentType } from '@standardnotes/domain-core'
|
||||
|
||||
const DEFAULT_MAJOR_CHANGE_THRESHOLD = 15
|
||||
const INVALID_SESSION_RESPONSE_STATUS = 401
|
||||
const TOO_MANY_REQUESTS_RESPONSE_STATUS = 429
|
||||
const DEFAULT_AUTO_SYNC_INTERVAL = 30_000
|
||||
|
||||
/** Content types appearing first are always mapped first */
|
||||
@@ -1000,6 +1001,10 @@ export class SyncService
|
||||
void this.notifyEvent(SyncEvent.InvalidSession)
|
||||
}
|
||||
|
||||
if (response.status === TOO_MANY_REQUESTS_RESPONSE_STATUS) {
|
||||
void this.notifyEvent(SyncEvent.TooManyRequests)
|
||||
}
|
||||
|
||||
this.opStatus?.setError(response.error)
|
||||
|
||||
void this.notifyEvent(SyncEvent.SyncError, response)
|
||||
|
||||
@@ -13,7 +13,7 @@ import { FunctionComponent, useCallback, useEffect, useMemo, useState, lazy, use
|
||||
import RevisionHistoryModal from '@/Components/RevisionHistoryModal/RevisionHistoryModal'
|
||||
import PremiumModalProvider from '@/Hooks/usePremiumModal'
|
||||
import ConfirmSignoutContainer from '@/Components/ConfirmSignoutModal/ConfirmSignoutModal'
|
||||
import { ToastContainer } from '@standardnotes/toast'
|
||||
import { addToast, ToastContainer, ToastType } from '@standardnotes/toast'
|
||||
import FilePreviewModalWrapper from '@/Components/FilePreview/FilePreviewModal'
|
||||
import FileContextMenuWrapper from '@/Components/FileContextMenu/FileContextMenu'
|
||||
import PermissionsModalWrapper from '@/Components/PermissionsModal/PermissionsModalWrapper'
|
||||
@@ -141,6 +141,11 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
|
||||
})
|
||||
.catch(console.error)
|
||||
}
|
||||
} else if (eventName === ApplicationEvent.SyncTooManyRequests) {
|
||||
addToast({
|
||||
type: ToastType.Error,
|
||||
message: 'Too many requests. Please try again later.',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user