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

chore(sitelaunch): better error message #1358

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
67 changes: 48 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 readonly siteLaunchLogger = parentLogger.child({
module: "formsgSiteLaunch",
})

constructor({ usersService, infraService }: FormsgSiteLaunchRouterProps) {
this.usersService = usersService
this.infraService = infraService
Expand Down Expand Up @@ -249,14 +259,21 @@ 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.`,
meta: {
domain: launchResult.primaryDomainSource,
},
})
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,
meta: {
domain: launchResult.primaryDomainSource,
},
})
throw e
}
}
Expand Down Expand Up @@ -313,19 +330,27 @@ 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.`,
meta: {
domain: launchResult.primaryDomainSource,
},
})

// 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,
meta: {
domain: launchResult.primaryDomainSource,
},
})
throw e
}
}
Expand Down Expand Up @@ -375,9 +400,13 @@ 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,
meta: {
submissionId,
},
})
}
}

Expand Down
Loading