Skip to content

Commit

Permalink
Handle mutation retries based on the http status code
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Dec 10, 2024
1 parent 6c217ba commit 9483765
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/backend/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {CMS} from 'alinea/core/CMS'
import {Connection} from 'alinea/core/Connection'
import {Draft, DraftKey, formatDraftKey} from 'alinea/core/Draft'
import {AnyQueryResult, Graph, GraphQuery} from 'alinea/core/Graph'
import {HttpError} from 'alinea/core/HttpError'
import {EditMutation, Mutation, MutationType} from 'alinea/core/Mutation'
import {PreviewUpdate} from 'alinea/core/Preview'
import {getScope} from 'alinea/core/Scope'
Expand Down Expand Up @@ -131,8 +132,8 @@ export function createHandler(
await Promise.all(tasks)
return {commitHash: result.commitHash}
} catch (error: any) {
if ('expectedCommitHash' in error) {
if (retry) throw error
if (retry) throw error
if (error instanceof HttpError && error.code === 409) {
await syncPending(ctx)
return mutate(ctx, mutations, true)
}
Expand Down

0 comments on commit 9483765

Please sign in to comment.