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/make login response indistinguishable #624

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 additions & 1 deletion src/routes/v2/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler")
const { FRONTEND_URL } = process.env
const { isSecure } = require("@utils/auth-utils")

const logger = require("@root/logger/logger")

const AUTH_TOKEN_EXPIRY_MS = parseInt(
process.env.AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS,
10
Expand Down Expand Up @@ -75,7 +77,14 @@ class AuthRouter {
async login(req, res) {
const { email: rawEmail } = req.body
const email = rawEmail.toLowerCase()
await this.authService.sendOtp(email)
try {
await this.authService.sendOtp(email)
} catch (err) {
// Log, but don't return so responses are indistinguishable
logger.log(
`Error occurred when attempting to login user ${email}: ${err}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably have structured logs so it makes querying easier in the future.

also, could we use logger.error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped to logger.error in e2f8173!

Currently our logger is initialised with no params, and our custom error middleware adds in the timestamp for each message - what kind of format were you thinking of adding?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was hoping for a object of something like

message: string,  
meta: Record<string, int>
timestamp: number

or something

)
}
return res.sendStatus(200)
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/identity/SmsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SmsClient {
try {
await this.axiosClient.post(endpoint, sms)
} catch (err) {
logger.error(err)
logger.error(`Failed to send SMS to ${recipient}: ${err}`)
throw new Error("Failed to send SMS.")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/utilServices/MailClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MailClient {
},
})
} catch (err) {
logger.error(err)
logger.error(`Error occurred when sending email to ${recipient}: ${err}`)
throw new Error("Failed to send email.")
}
}
Expand Down