-
-
Notifications
You must be signed in to change notification settings - Fork 10
fix(auth,orgs,audit): replace silent .catch(() => {}) with error logging #3366
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
Changes from 1 commit
9d649bf
67269ac
ebad7a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import AuthOrganizationService from '../../organizations/services/organizations. | |||||||||||||||||||
| import OrganizationCrudService from '../../organizations/services/organizations.crud.service.js'; | ||||||||||||||||||||
| import MembershipService from '../../organizations/services/organizations.membership.service.js'; | ||||||||||||||||||||
| import AnalyticsService from '../../../lib/services/analytics.js'; | ||||||||||||||||||||
| import logger from '../../../lib/services/logger.js'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const tokenCookieOptions = { | ||||||||||||||||||||
| httpOnly: true, | ||||||||||||||||||||
|
|
@@ -79,7 +80,7 @@ const signup = async (req, res) => { | |||||||||||||||||||
| emailVerificationExpires: Date.now() + 24 * 3600000, // 24 hours | ||||||||||||||||||||
| }, 'recover'); | ||||||||||||||||||||
| // Send verification email (best-effort, do not block signup) | ||||||||||||||||||||
| sendVerificationEmail(user, verificationToken).catch(() => {}); | ||||||||||||||||||||
| sendVerificationEmail(user, verificationToken).catch((err) => logger.warn('auth.signup: verification email failed', err)); | ||||||||||||||||||||
|
||||||||||||||||||||
| sendVerificationEmail(user, verificationToken).catch((err) => logger.warn('auth.signup: verification email failed', err)); | |
| sendVerificationEmail(user, verificationToken).catch((err) => logger.warn( | |
| 'auth.signup: verification email failed', | |
| { | |
| message: err && err.message, | |
| stack: err && err.stack, | |
| name: err && err.name, | |
| }, | |
| )); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import getBaseUrl from '../../../lib/helpers/getBaseUrl.js'; | |||||
| import errors from '../../../lib/helpers/errors.js'; | ||||||
| import responses from '../../../lib/helpers/responses.js'; | ||||||
| import config from '../../../config/index.js'; | ||||||
| import logger from '../../../lib/services/logger.js'; | ||||||
|
|
||||||
| const tokenCookieOptions = { | ||||||
| httpOnly: true, | ||||||
|
|
@@ -108,7 +109,7 @@ const reset = async (req, res) => { | |||||
| appName: config.app.title, | ||||||
| appContact: config.app.contact, | ||||||
| }, | ||||||
| }).catch(() => {}); | ||||||
| }).catch((err) => logger.warn('auth.password.reset: confirmation email failed', err)); | ||||||
|
||||||
| }).catch((err) => logger.warn('auth.password.reset: confirmation email failed', err)); | |
| }).catch((err) => logger.warn('auth.password.reset: confirmation email failed', { error: { message: err?.message, stack: err?.stack } })); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||||||||
| import AppError from '../../../lib/helpers/AppError.js'; | ||||||||||||||||||||||||||||||||||
| import { assertEmailVerified } from '../../../lib/helpers/emailVerification.js'; | ||||||||||||||||||||||||||||||||||
| import config from '../../../config/index.js'; | ||||||||||||||||||||||||||||||||||
| import logger from '../../../lib/services/logger.js'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * @desc Escape regex-special characters in a user-provided string. | ||||||||||||||||||||||||||||||||||
|
|
@@ -112,8 +113,8 @@ const create = async (body, user) => { | |||||||||||||||||||||||||||||||||
| await UserService.updateById(user.id || user._id, { currentOrganization: result._id }); | ||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||
| // Rollback partially created artifacts | ||||||||||||||||||||||||||||||||||
| if (membership) await MembershipRepository.deleteMany({ _id: membership._id }).catch(() => {}); | ||||||||||||||||||||||||||||||||||
| await OrganizationsRepository.remove(result).catch(() => {}); | ||||||||||||||||||||||||||||||||||
| if (membership) await MembershipRepository.deleteMany({ _id: membership._id }).catch((e) => logger.error('organizations.crud.create: rollback membership failed', e)); | ||||||||||||||||||||||||||||||||||
| await OrganizationsRepository.remove(result).catch((e) => logger.error('organizations.crud.create: rollback organization failed', e)); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| if (membership) await MembershipRepository.deleteMany({ _id: membership._id }).catch((e) => logger.error('organizations.crud.create: rollback membership failed', e)); | |
| await OrganizationsRepository.remove(result).catch((e) => logger.error('organizations.crud.create: rollback organization failed', e)); | |
| if (membership) { | |
| await MembershipRepository.deleteMany({ _id: membership._id }).catch((e) => | |
| logger.error('organizations.crud.create: rollback membership failed', { | |
| message: e?.message, | |
| stack: e?.stack, | |
| }), | |
| ); | |
| } | |
| await OrganizationsRepository.remove(result).catch((e) => | |
| logger.error('organizations.crud.create: rollback organization failed', { | |
| message: e?.message, | |
| stack: e?.stack, | |
| }), | |
| ); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||
| import crypto from 'crypto'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import config from '../../../config/index.js'; | ||||||||||||||||||||||||||||
| import logger from '../../../lib/services/logger.js'; | ||||||||||||||||||||||||||||
| import getBaseUrl from '../../../lib/helpers/getBaseUrl.js'; | ||||||||||||||||||||||||||||
| import mailer from '../../../lib/helpers/mailer/index.js'; | ||||||||||||||||||||||||||||
| import { assertEmailVerified } from '../../../lib/helpers/emailVerification.js'; | ||||||||||||||||||||||||||||
|
|
@@ -164,7 +165,7 @@ const createJoinRequest = async (userId, organizationId) => { | |||||||||||||||||||||||||||
| url: `${getBaseUrl()}/users/organizations/${organizationId}`, | ||||||||||||||||||||||||||||
| appName: config.app.title, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }).catch(() => {}); | ||||||||||||||||||||||||||||
| }).catch((err) => logger.warn('organizations.membership.createJoinRequest: admin notification email failed', err)); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| }).catch((err) => logger.warn('organizations.membership.createJoinRequest: admin notification email failed', err)); | |
| }).catch((err) => | |
| logger.warn( | |
| 'organizations.membership.createJoinRequest: admin notification email failed', | |
| { message: err?.message, stack: err?.stack } | |
| ) | |
| ); |
Copilot
AI
Mar 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same JSON-logging concern: logging the raw Error object as metadata may not include message/stack. Prefer serializable fields (e.g. { message: err?.message, stack: err?.stack }) so the warning is useful in production logs.
Copilot
AI
Mar 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same JSON-logging concern here: passing err directly may serialize to {} under winston.format.json(). Prefer logging serializable error details (message/stack) so this warning remains informative in production.
| }).catch((err) => logger.warn('organizations.membership.rejectRequest: rejection email failed', err)); | |
| }).catch((err) => | |
| logger.warn( | |
| 'organizations.membership.rejectRequest: rejection email failed', | |
| { | |
| error: { | |
| message: err && err.message, | |
| stack: err && err.stack, | |
| name: err && err.name, | |
| }, | |
| }, | |
| ), | |
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| */ | ||
| import config from '../../../config/index.js'; | ||
| import mailer from '../../../lib/helpers/mailer/index.js'; | ||
| import logger from '../../../lib/services/logger.js'; | ||
| import policy from '../../../lib/middlewares/policy.js'; | ||
| import serializeAbilities from '../../../lib/helpers/abilities.js'; | ||
| import OrganizationsRepository from '../repositories/organizations.repository.js'; | ||
|
|
@@ -98,10 +99,10 @@ const createOrganizationForUser = async ({ name, slug, domain, user, slugGenerat | |
| } catch (err) { | ||
| // Clean up any partially created artifacts to avoid orphaned records | ||
| if (membership) { | ||
| await MembershipRepository.deleteMany({ _id: membership._id }).catch(() => {}); | ||
| await MembershipRepository.deleteMany({ _id: membership._id }).catch((e) => logger.error('organizations.service.createOrganizationForUser: rollback membership failed', e)); | ||
| } | ||
| if (organization) { | ||
| await OrganizationsRepository.remove(organization).catch(() => {}); | ||
| await OrganizationsRepository.remove(organization).catch((e) => logger.error('organizations.service.createOrganizationForUser: rollback organization failed', e)); | ||
|
||
| } | ||
| // Retry on MongoDB duplicate key error for slug collisions (TOCTOU race) | ||
| if (err.code === 11000 && err.message?.includes('slug') && attempt < maxRetries - 1) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuditService.log()already wrapsAuditRepository.create()in a try/catch and never rejects (it logs and returnsnullon failure). That means this.catch(...)will never run, and the extra logger import is effectively dead code. Consider removing this.catch(and the logger import) and relying onAuditService.log()'s internal logging, or adjustAuditService.log()to rethrow if you want the middleware-level catch to be meaningful.