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

fix(application-system-api-worker): Get template error catch #17186

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,39 +151,52 @@ export class ApplicationLifeCycleService {
private async preparePrunedNotification(
application: PruningApplication,
): Promise<CreateHnippNotificationDto | null> {
const template = await getApplicationTemplateByTypeId(application.typeId)
const stateConfig = template.stateMachineConfig.states[application.state]
const lifeCycle = stateConfig.meta?.lifecycle
if (lifeCycle && lifeCycle.shouldBePruned && lifeCycle.pruneMessage) {
try {
const pruneMessage =
typeof lifeCycle.pruneMessage === 'function'
? lifeCycle.pruneMessage(application as ApplicationWithAttachments)
: lifeCycle.pruneMessage
const notification = {
recipient: application.applicant,
templateId: pruneMessage.notificationTemplateId,
args: [
{
key: 'externalBody',
value: pruneMessage.externalBody || '',
},
{
key: 'internalBody',
value: pruneMessage.internalBody || '',
},
],
}
return notification
} catch (error) {
this.logger.error(
`Failed to prepare pruning notification for application ${application.id}`,
error,
)
try {
const template = await getApplicationTemplateByTypeId(application.typeId)
if (!template) {
return null
}
const stateConfig = template.stateMachineConfig.states[application.state]
const lifeCycle = stateConfig.meta?.lifecycle
if (lifeCycle && lifeCycle.shouldBePruned && lifeCycle.pruneMessage) {
obmagnusson marked this conversation as resolved.
Show resolved Hide resolved
try {
const pruneMessage =
typeof lifeCycle.pruneMessage === 'function'
? lifeCycle.pruneMessage(
application as ApplicationWithAttachments,
)
: lifeCycle.pruneMessage
const notification = {
recipient: application.applicant,
templateId: pruneMessage.notificationTemplateId,
args: [
{
key: 'externalBody',
value: pruneMessage.externalBody || '',
},
{
key: 'internalBody',
value: pruneMessage.internalBody || '',
},
],
}
return notification
} catch (error) {
this.logger.error(
`Failed to prepare pruning notification for application ${application.id}`,
error,
)
return null
}
}
return null
} catch (error) {
this.logger.error(
`Failed to get application template for application typeId ${application.typeId}`,
error,
)
return null
}
return null
}

private async sendPrunedNotification(
Expand Down
Loading