Skip to content

Commit 657e98c

Browse files
committed
Changes after review
1 parent c97a090 commit 657e98c

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/repositories/save-and-exit-repository.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export async function createSaveAndExitRecord(recordInput, session) {
6363
magicLinkGroupId: recordInput.magicLinkGroupId,
6464
consumed: { $ne: true }
6565
},
66-
{ $set: { consumed: true } }
66+
{ $set: { consumed: true } },
67+
{ session }
6768
)
6869
}
6970

src/services/save-and-exit-service.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getErrorMessage } from '@defra/forms-model'
12
import Boom from '@hapi/boom'
23
import argon2 from 'argon2'
34

@@ -90,15 +91,26 @@ export async function resetSaveAndExitLink(magicLinkId) {
9091
* @param {ClientSession} session
9192
*/
9293
export async function cleanUpSaveAndExit(meta, session) {
93-
const magicLinkGroupId = meta.custom?.magicLinkGroupId
94-
if (!magicLinkGroupId) {
95-
return
96-
}
94+
try {
95+
const magicLinkGroupId = meta.custom?.magicLinkGroupId
96+
if (!magicLinkGroupId) {
97+
return
98+
}
9799

98-
await deleteSaveAndExitGroup(
99-
/** @type {string} */ (magicLinkGroupId),
100-
session
101-
)
100+
await deleteSaveAndExitGroup(
101+
/** @type {string} */ (magicLinkGroupId),
102+
session
103+
)
104+
} catch (err) {
105+
const groupId = /** @type {string | undefined} */ (
106+
meta.custom?.magicLinkGroupId
107+
)
108+
logger.error(
109+
err,
110+
`[cleanSaveAndExit] Failed to delete old save-and-exit records of group ${groupId}: ${getErrorMessage(err)}`
111+
)
112+
// Silently fail otherwise submission would go to DLQ even though it's been processed ok
113+
}
102114
}
103115

104116
/**

0 commit comments

Comments
 (0)