Overview
User handling incidents typically stem from:- Unhandled promise rejections in async operations
- Missing null/undefined checks on optional fields
- Improper error propagation in async/await code
Incidents
INC-101: Unhandled Promise Rejection on User Fetch
INC-101: Unhandled Promise Rejection on User Fetch
Summary
Severity: P1 - CriticalService: node-service
Date: 2026-02-28
Environment: ProductionThe Node.js service crashed when fetching non-existent user profiles due to an unhandled promise rejection. The server process exited instead of returning a 404 response.
Problem
When requesting a user ID that doesn’t exist in the database, theuserService.getById() method threw an error that wasn’t caught in the route handler. This caused the entire server process to crash with an unhandled promise rejection.Error message:Root Cause
During migration from callbacks to async/await, the route handler at/api/users/:id was not wrapped in a try-catch block:Problematic code (src/routes/users.js:9-12):userService.getById() throws an error when a user is not found, but there’s no error handling around this async operation.Resolution
Wrap the async operation in a try-catch block and return appropriate HTTP status codes:Fixed code:Prevention
- Always wrap async route handlers in try-catch blocks
- Use an async error handling middleware for Express routes
- Consider using
express-async-errorspackage to automatically catch async errors - Add process-level handlers for unhandled rejections as a safety net:
INC-107: Null Reference Error on User Profile
INC-107: Null Reference Error on User Profile
Summary
Severity: P1 - CriticalService: node-service
Date: 2026-02-28
Environment: ProductionServer crashed with “Cannot read properties of undefined (reading ‘avatar’)” when fetching profiles of users who haven’t completed onboarding. Affected approximately 30% of users who signed up but never completed their profile.
Problem
TheformatUserResponse() utility function accessed nested properties without checking if the parent object exists.Error message:Root Cause
The formatter assumesuser.profile always exists, but newly registered users have profile set to null or undefined by default.Problematic code (src/utils/formatters.js:4-14):Resolution
Add null safety checks and provide default values:Fixed code:Prevention
- Use optional chaining (
?.) when accessing nested properties - Provide sensible defaults for optional fields
- Consider TypeScript for compile-time null safety checks
- Add integration tests for users in various states (new, partial profile, complete profile)
- Document which fields are nullable in your data models