Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: let user know about 429 status #2747

Merged
merged 1 commit into from Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/services/src/Domain/Event/ApplicationEvent.ts
Expand Up @@ -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',
}
1 change: 1 addition & 0 deletions packages/services/src/Domain/Event/SyncEvent.ts
Expand Up @@ -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[]
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/lib/Application/Event.ts
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions packages/snjs/lib/Services/Sync/SyncService.ts
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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'
Expand Down Expand Up @@ -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.',
})
}
})

Expand Down