Skip to content

Commit

Permalink
chore(application-templates-driving-license): instrumenting more logg…
Browse files Browse the repository at this point in the history
…ing in the submit application action (#6197)

* chore(application-templates-driving-license): instrumenting more logging in the submit application action

* import type Logger

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
arnorhs and kodiakhq[bot] authored Jan 11, 2022
1 parent 29380fe commit 795fb6d
Showing 1 changed file with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import {
DrivingLicenseService,
NewDrivingLicenseResult,
Expand All @@ -11,6 +11,8 @@ import {
generateDrivingLicenseSubmittedEmail,
generateDrivingAssessmentApprovalEmail,
} from './emailGenerators'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

const calculateNeedsHealthCert = (healthDeclaration = {}) => {
return !!Object.values(healthDeclaration).find((val) => val === 'yes')
Expand All @@ -19,6 +21,7 @@ const calculateNeedsHealthCert = (healthDeclaration = {}) => {
@Injectable()
export class DrivingLicenseSubmissionService {
constructor(
@Inject(LOGGER_PROVIDER) private logger: Logger,
private readonly drivingLicenseService: DrivingLicenseService,
private readonly sharedTemplateAPIService: SharedTemplateApiService,
) {}
Expand Down Expand Up @@ -67,27 +70,45 @@ export class DrivingLicenseSubmissionService {
}
}

const result = await this.createLicense(nationalId, answers).catch((e) => {
return {
success: false,
errorMessage: e.message,
}
})
let result
try {
result = await this.createLicense(nationalId, answers)
} catch (e) {
this.log('error', 'Creating license failed', {
e,
applicationFor: answers.applicationFor,
jurisdiction: answers.juristictionId,
})

throw e
}

if (!result.success) {
throw new Error(`Application submission failed (${result.errorMessage})`)
}

await this.sharedTemplateAPIService.sendEmail(
generateDrivingLicenseSubmittedEmail,
application,
)
try {
await this.sharedTemplateAPIService.sendEmail(
generateDrivingLicenseSubmittedEmail,
application,
)
} catch (e) {
this.log(
'error',
'Could not send email to applicant after successful submission',
{ e },
)
}

return {
success: result.success,
success: true,
}
}

private log(lvl: 'error' | 'info', message: string, meta: unknown) {
this.logger.log(lvl, `[driving-license-submission] ${message}`, meta)
}

private async createLicense(
nationalId: string,
answers: FormValue,
Expand Down

0 comments on commit 795fb6d

Please sign in to comment.