Skip to content

Commit 511cb82

Browse files
committed
fix(backend): propagate failure when granting data access
addDataAccessUser returns a Rejection rather than throwing, and the empty else branch discarded it. The caller then stamped claimedAt, so a failed insert burned the invite, granted nothing, and reported success with no log or event. Throw the Rejection (it extends GraphQLError) so the accept aborts before the invite is marked claimed. Removes both TODOs.
1 parent e8d29e8 commit 511cb82

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

apps/backend/src/mutations/InviteMutations.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -482,27 +482,26 @@ export default class InviteMutations {
482482
continue;
483483
}
484484

485-
// TODO: what happens if there is an error during accept?
486-
// we need graceful error handling from the database later
487-
const isRejection =
488-
await this.dataAccessUsersDataSource.addDataAccessUser(
489-
claim.proposalPk,
490-
claimerUserId
491-
);
485+
const failure = await this.dataAccessUsersDataSource.addDataAccessUser(
486+
claim.proposalPk,
487+
claimerUserId
488+
);
492489

493-
if (!isRejection) {
494-
this.eventBus.publish({
495-
type: Event.PROPOSAL_DATA_ACCESS_INVITE_ACCEPTED,
496-
isRejection: false,
497-
key: 'proposal',
498-
loggedInUserId: claimerUserId,
499-
invite: invite,
500-
description: `User with ID ${claimerUserId} accepted data access invite for proposal ${claim.proposalPk}`,
501-
proposalPKey: claim.proposalPk,
502-
});
503-
} else {
504-
// TODO: what happens if there is an error during accept?
490+
// Rejection extends GraphQLError, so throwing aborts the accept before
491+
// the invite is stamped as claimed.
492+
if (failure) {
493+
throw failure;
505494
}
495+
496+
this.eventBus.publish({
497+
type: Event.PROPOSAL_DATA_ACCESS_INVITE_ACCEPTED,
498+
isRejection: false,
499+
key: 'proposal',
500+
loggedInUserId: claimerUserId,
501+
invite: invite,
502+
description: `User with ID ${claimerUserId} accepted data access invite for proposal ${claim.proposalPk}`,
503+
proposalPKey: claim.proposalPk,
504+
});
506505
}
507506
}
508507

0 commit comments

Comments
 (0)