Skip to content

Commit

Permalink
chore(sitelaunch): better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed May 2, 2024
1 parent a840ed0 commit 2c05f01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class Logger {
return new Logger(child)
}

public setBindings = (bindings: { [key: string]: unknown }): void => {
this._logger.setBindings(bindings)
}

public error = (
// NOTE: Giving type as `unknown` here
// because when we do a `catch`,
Expand Down
58 changes: 39 additions & 19 deletions support/routes/v2/formsg/formsgSiteLaunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { err, ok } from "neverthrow"

import { config } from "@config/config"

import logger from "@logger/logger"
import parentLogger from "@logger/logger"

import InitializationError from "@errors/InitializationError"

Expand Down Expand Up @@ -85,9 +85,15 @@ export class FormsgSiteLaunchRouter {
},
]

logger.info(
`Launch site form submission [${submissionId}] (repoName '${repoName}', domain '${primaryDomain}') requested by <${requesterEmail}>`
)
this.siteLaunchLogger.info({
message: "Launch site form submission",
meta: {
submissionId,
repoName,
primaryDomain,
requesterEmail,
},
})

// 2. Check arguments
if (!requesterEmail) {
Expand Down Expand Up @@ -147,6 +153,10 @@ export class FormsgSiteLaunchRouter {

private readonly infraService: FormsgSiteLaunchRouterProps["infraService"]

private siteLaunchLogger = parentLogger.child({
module: "formsgSiteLaunch",
})

constructor({ usersService, infraService }: FormsgSiteLaunchRouterProps) {
this.usersService = usersService
this.infraService = infraService
Expand Down Expand Up @@ -204,6 +214,12 @@ export class FormsgSiteLaunchRouter {
) || []

res.sendStatus(200) // we have received the form and obtained relevant field
this.siteLaunchLogger.setBindings({
submissionId,
primaryDomain: Array.from(
new Set(formResponses.map((x) => x.primaryDomain))
),
})
this.handleSiteLaunchResults(formResponses, submissionId)
}

Expand Down Expand Up @@ -249,14 +265,15 @@ export class FormsgSiteLaunchRouter {
}))
} catch (e) {
if (isErrnoException(e) && e.code === "ENODATA") {
logger.info(
`Domain ${launchResult.primaryDomainSource} does not have any AAAA records.`
)
this.siteLaunchLogger.info({
message: `Domain does not have any AAAA records.`,
})
return [] // no AAAA records found
}
logger.error(
`Error when trying to get AAAA records for domain ${launchResult.primaryDomainSource}: ${e}`
)
this.siteLaunchLogger.error({
message: "Error when trying to get AAAA records for domain",
error: e,
})
throw e
}
}
Expand Down Expand Up @@ -313,19 +330,21 @@ export class FormsgSiteLaunchRouter {
return result
} catch (e) {
if (isErrnoException(e) && e.code === "ENODATA") {
logger.info(
`Domain ${launchResult.primaryDomainSource} does not have any CAA records.`
)
this.siteLaunchLogger.info({
message: `Domain does not have any CAA records.`,
})

// if no CAA records, no need to add Amazon CAA and letsencrypt.org CAA
return {
addAWSACMCertCAA: false,
addLetsEncryptCAA: false,
}
}
logger.error(
`Error when trying to get CAA records for domain ${launchResult.primaryDomainSource}: ${e}`
)

this.siteLaunchLogger.error({
message: "Error when trying to get CAA records for domain",
error: e,
})
throw e
}
}
Expand Down Expand Up @@ -375,9 +394,10 @@ export class FormsgSiteLaunchRouter {

await this.sendLaunchError(submissionId, failureResults)
} catch (e) {
logger.error(
`Something unexpected went wrong when launching sites from form submission ${submissionId}. Error: ${e}`
)
this.siteLaunchLogger.error({
message: `Something unexpected went wrong when launching sites from form submission`,
error: e,
})
}
}

Expand Down

0 comments on commit 2c05f01

Please sign in to comment.