Skip to content

Commit

Permalink
chore: let user know about 429 status (#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Jan 8, 2024
1 parent fe2daa1 commit a70cac0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/services/src/Domain/Event/ApplicationEvent.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a70cac0

Please sign in to comment.