added stack trace to some logging
This commit is contained in:
@@ -36,6 +36,34 @@ const apiLogger = (req, res, next) => {
|
|||||||
userId: req.user?.id || 'anonymous'
|
userId: req.user?.id || 'anonymous'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Parse response body for error responses to include error details
|
||||||
|
if (res.statusCode >= 400) {
|
||||||
|
let errorDetails = null;
|
||||||
|
if (body) {
|
||||||
|
try {
|
||||||
|
const parsed = typeof body === 'string' ? JSON.parse(body) : body;
|
||||||
|
// Extract error message, validation errors, or full response
|
||||||
|
errorDetails = {
|
||||||
|
error: parsed.error || parsed.message || null,
|
||||||
|
errors: parsed.errors || null, // validation errors array
|
||||||
|
details: parsed.details || null
|
||||||
|
};
|
||||||
|
// Remove null values
|
||||||
|
Object.keys(errorDetails).forEach(key => {
|
||||||
|
if (errorDetails[key] === null) delete errorDetails[key];
|
||||||
|
});
|
||||||
|
if (Object.keys(errorDetails).length > 0) {
|
||||||
|
responseData.errorDetails = errorDetails;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Body is not JSON, include as string (truncated)
|
||||||
|
if (typeof body === 'string' && body.length > 0) {
|
||||||
|
responseData.errorDetails = { raw: body.substring(0, 500) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||||
// Don't log 401s for /users/profile - these are expected auth checks
|
// Don't log 401s for /users/profile - these are expected auth checks
|
||||||
if (!(res.statusCode === 401 && req.url === '/profile')) {
|
if (!(res.statusCode === 401 && req.url === '/profile')) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const rateLimit = require("express-rate-limit");
|
const rateLimit = require("express-rate-limit");
|
||||||
|
const logger = require("../utils/logger");
|
||||||
|
|
||||||
// General rate limiter for Maps API endpoints
|
// General rate limiter for Maps API endpoints
|
||||||
const createMapsRateLimiter = (windowMs, max, message) => {
|
const createMapsRateLimiter = (windowMs, max, message) => {
|
||||||
@@ -111,6 +112,21 @@ const uploadPresignLimiter = createUserBasedRateLimiter(
|
|||||||
"Too many upload requests. Please slow down."
|
"Too many upload requests. Please slow down."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Helper to create a rate limit handler that logs the event
|
||||||
|
const createRateLimitHandler = (limiterName) => (req, res, next, options) => {
|
||||||
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
|
reqLogger.warn('Rate limit exceeded', {
|
||||||
|
limiter: limiterName,
|
||||||
|
ip: req.ip,
|
||||||
|
userId: req.user?.id || 'anonymous',
|
||||||
|
method: req.method,
|
||||||
|
url: req.url,
|
||||||
|
userAgent: req.get('User-Agent'),
|
||||||
|
message: options.message?.error || 'Rate limit exceeded'
|
||||||
|
});
|
||||||
|
res.status(options.statusCode).json(options.message);
|
||||||
|
};
|
||||||
|
|
||||||
// Authentication rate limiters
|
// Authentication rate limiters
|
||||||
const authRateLimiters = {
|
const authRateLimiters = {
|
||||||
// Login rate limiter - stricter to prevent brute force
|
// Login rate limiter - stricter to prevent brute force
|
||||||
@@ -124,6 +140,7 @@ const authRateLimiters = {
|
|||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
skipSuccessfulRequests: true, // Don't count successful logins
|
skipSuccessfulRequests: true, // Don't count successful logins
|
||||||
|
handler: createRateLimitHandler('login'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Registration rate limiter
|
// Registration rate limiter
|
||||||
@@ -136,6 +153,7 @@ const authRateLimiters = {
|
|||||||
},
|
},
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
handler: createRateLimitHandler('register'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Password reset rate limiter
|
// Password reset rate limiter
|
||||||
@@ -148,6 +166,7 @@ const authRateLimiters = {
|
|||||||
},
|
},
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
handler: createRateLimitHandler('passwordReset'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Alpha code validation rate limiter
|
// Alpha code validation rate limiter
|
||||||
@@ -160,6 +179,7 @@ const authRateLimiters = {
|
|||||||
},
|
},
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
handler: createRateLimitHandler('alphaCodeValidation'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Email verification rate limiter - protect against brute force on 6-digit codes
|
// Email verification rate limiter - protect against brute force on 6-digit codes
|
||||||
@@ -172,6 +192,7 @@ const authRateLimiters = {
|
|||||||
},
|
},
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
handler: createRateLimitHandler('emailVerification'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// General API rate limiter
|
// General API rate limiter
|
||||||
@@ -184,6 +205,7 @@ const authRateLimiters = {
|
|||||||
},
|
},
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
|
handler: createRateLimitHandler('general'),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ router.post(
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send verification email", {
|
reqLogger.error("Failed to send verification email", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
});
|
});
|
||||||
@@ -645,6 +646,7 @@ router.post(
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to resend verification email", {
|
reqLogger.error("Failed to resend verification email", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
});
|
});
|
||||||
@@ -819,6 +821,7 @@ router.post(
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send password reset email", {
|
reqLogger.error("Failed to send password reset email", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
});
|
});
|
||||||
@@ -960,6 +963,7 @@ router.post(
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send password changed notification", {
|
reqLogger.error("Failed to send password changed notification", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ router.post("/:rentalId", authenticateToken, async (req, res) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error submitting condition check", {
|
reqLogger.error("Error submitting condition check", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
rentalId: req.params.rentalId,
|
rentalId: req.params.rentalId,
|
||||||
userId: req.user?.id,
|
userId: req.user?.id,
|
||||||
});
|
});
|
||||||
@@ -85,6 +86,7 @@ router.get("/:rentalId", authenticateToken, async (req, res) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error fetching condition checks", {
|
reqLogger.error("Error fetching condition checks", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
rentalId: req.params.rentalId,
|
rentalId: req.params.rentalId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -112,6 +114,7 @@ router.get("/:rentalId/timeline", authenticateToken, async (req, res) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error fetching condition check timeline", {
|
reqLogger.error("Error fetching condition check timeline", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
rentalId: req.params.rentalId,
|
rentalId: req.params.rentalId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,6 +142,7 @@ router.get("/", authenticateToken, async (req, res) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error fetching available checks", {
|
reqLogger.error("Error fetching available checks", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
userId: req.user?.id,
|
userId: req.user?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ router.post('/', authenticateToken, sanitizeInput, validateFeedback, async (req,
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
reqLogger.error("Failed to send feedback confirmation email", {
|
reqLogger.error("Failed to send feedback confirmation email", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
feedbackId: feedback.id
|
feedbackId: feedback.id
|
||||||
});
|
});
|
||||||
@@ -45,6 +46,7 @@ router.post('/', authenticateToken, sanitizeInput, validateFeedback, async (req,
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
reqLogger.error("Failed to send feedback notification to admin", {
|
reqLogger.error("Failed to send feedback notification to admin", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
feedbackId: feedback.id
|
feedbackId: feedback.id
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ router.post('/posts', authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Geocoding failed for item request", {
|
reqLogger.error("Geocoding failed for item request", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
zipCode
|
zipCode
|
||||||
});
|
});
|
||||||
// Continue without coordinates - post will still be created
|
// Continue without coordinates - post will still be created
|
||||||
@@ -450,6 +451,7 @@ router.post('/posts', authenticateToken, async (req, res, next) => {
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
logger.error("Failed to send item request notification", {
|
logger.error("Failed to send item request notification", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
recipientId: user.id,
|
recipientId: user.id,
|
||||||
postId: post.id
|
postId: post.id
|
||||||
});
|
});
|
||||||
@@ -1383,7 +1385,12 @@ router.delete('/admin/posts/:id', authenticateToken, requireAdmin, async (req, r
|
|||||||
}
|
}
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
// Log but don't fail the deletion
|
// Log but don't fail the deletion
|
||||||
console.error('Failed to send forum post deletion notification email:', emailError.message);
|
logger.error('Failed to send forum post deletion notification email', {
|
||||||
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
|
postId: post.id,
|
||||||
|
authorId: post.authorId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -1511,7 +1518,12 @@ router.delete('/admin/comments/:id', authenticateToken, requireAdmin, async (req
|
|||||||
}
|
}
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
// Log but don't fail the deletion
|
// Log but don't fail the deletion
|
||||||
console.error('Failed to send forum comment deletion notification email:', emailError.message);
|
logger.error('Failed to send forum comment deletion notification email', {
|
||||||
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
|
commentId: comment.id,
|
||||||
|
authorId: comment.authorId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -372,10 +372,17 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res, next)
|
|||||||
itemWithOwner.owner,
|
itemWithOwner.owner,
|
||||||
itemWithOwner
|
itemWithOwner
|
||||||
);
|
);
|
||||||
console.log(`First listing celebration email sent to owner ${req.user.id}`);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
|
reqLogger.info("First listing celebration email sent", { ownerId: req.user.id });
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
// Log but don't fail the item creation
|
// Log but don't fail the item creation
|
||||||
console.error('Failed to send first listing celebration email:', emailError.message);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
|
reqLogger.error('Failed to send first listing celebration email', {
|
||||||
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
|
ownerId: req.user.id,
|
||||||
|
itemId: item.id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,10 +578,15 @@ router.delete("/admin/:id", authenticateToken, requireAdmin, async (req, res, ne
|
|||||||
item,
|
item,
|
||||||
reason.trim()
|
reason.trim()
|
||||||
);
|
);
|
||||||
console.log(`Item deletion notification email sent to owner ${item.ownerId}`);
|
logger.info("Item deletion notification email sent", { ownerId: item.ownerId, itemId: item.id });
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
// Log but don't fail the deletion
|
// Log but don't fail the deletion
|
||||||
console.error('Failed to send item deletion notification email:', emailError.message);
|
logger.error('Failed to send item deletion notification email', {
|
||||||
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
|
ownerId: item.ownerId,
|
||||||
|
itemId: item.id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ router.post('/', authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send message notification email", {
|
reqLogger.error("Failed to send message notification email", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
receiverId: receiverId
|
receiverId: receiverId
|
||||||
});
|
});
|
||||||
@@ -436,6 +437,7 @@ router.get('/images/:filename',
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error('Image serve failed', {
|
reqLogger.error('Image serve failed', {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
filename: req.params.filename
|
filename: req.params.filename
|
||||||
});
|
});
|
||||||
res.status(500).json({ error: 'Failed to load image' });
|
res.status(500).json({ error: 'Failed to load image' });
|
||||||
|
|||||||
@@ -466,6 +466,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
|||||||
"Failed to send rental approval confirmation email to owner",
|
"Failed to send rental approval confirmation email to owner",
|
||||||
{
|
{
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId: updatedRental.id,
|
rentalId: updatedRental.id,
|
||||||
ownerId: updatedRental.ownerId,
|
ownerId: updatedRental.ownerId,
|
||||||
}
|
}
|
||||||
@@ -505,6 +506,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
|||||||
"Failed to send rental confirmation email to renter",
|
"Failed to send rental confirmation email to renter",
|
||||||
{
|
{
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId: updatedRental.id,
|
rentalId: updatedRental.id,
|
||||||
renterId: updatedRental.renterId,
|
renterId: updatedRental.renterId,
|
||||||
}
|
}
|
||||||
@@ -568,6 +570,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
|||||||
"Failed to send rental approval confirmation email to owner",
|
"Failed to send rental approval confirmation email to owner",
|
||||||
{
|
{
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId: updatedRental.id,
|
rentalId: updatedRental.id,
|
||||||
ownerId: updatedRental.ownerId,
|
ownerId: updatedRental.ownerId,
|
||||||
}
|
}
|
||||||
@@ -607,6 +610,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
|||||||
"Failed to send rental confirmation email to renter",
|
"Failed to send rental confirmation email to renter",
|
||||||
{
|
{
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId: updatedRental.id,
|
rentalId: updatedRental.id,
|
||||||
renterId: updatedRental.renterId,
|
renterId: updatedRental.renterId,
|
||||||
}
|
}
|
||||||
@@ -1112,6 +1116,7 @@ router.post("/:id/cancel", authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send cancellation emails", {
|
reqLogger.error("Failed to send cancellation emails", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId: updatedRental.id,
|
rentalId: updatedRental.id,
|
||||||
cancelledBy: updatedRental.cancelledBy,
|
cancelledBy: updatedRental.cancelledBy,
|
||||||
});
|
});
|
||||||
@@ -1206,6 +1211,7 @@ router.post("/:id/mark-return", authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Failed to send rental completion emails", {
|
reqLogger.error("Failed to send rental completion emails", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
rentalId,
|
rentalId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1294,6 +1300,7 @@ router.post("/:id/mark-return", authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error marking return status", {
|
reqLogger.error("Error marking return status", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
rentalId: req.params.id,
|
rentalId: req.params.id,
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
});
|
});
|
||||||
@@ -1376,6 +1383,7 @@ router.post("/:id/report-damage", authenticateToken, async (req, res, next) => {
|
|||||||
const reqLogger = logger.withRequestId(req.id);
|
const reqLogger = logger.withRequestId(req.id);
|
||||||
reqLogger.error("Error reporting damage", {
|
reqLogger.error("Error reporting damage", {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
rentalId: req.params.id,
|
rentalId: req.params.id,
|
||||||
userId: req.user.id,
|
userId: req.user.id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class UserService {
|
|||||||
"Failed to send personal information changed notification",
|
"Failed to send personal information changed notification",
|
||||||
{
|
{
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
changedFields,
|
changedFields,
|
||||||
@@ -138,6 +139,7 @@ class UserService {
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
logger.error("Failed to send notification for address creation", {
|
logger.error("Failed to send notification for address creation", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
addressId: address.id,
|
addressId: address.id,
|
||||||
});
|
});
|
||||||
@@ -181,6 +183,7 @@ class UserService {
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
logger.error("Failed to send notification for address update", {
|
logger.error("Failed to send notification for address update", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId,
|
userId,
|
||||||
addressId: address.id,
|
addressId: address.id,
|
||||||
});
|
});
|
||||||
@@ -223,6 +226,7 @@ class UserService {
|
|||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
logger.error("Failed to send notification for address deletion", {
|
logger.error("Failed to send notification for address deletion", {
|
||||||
error: emailError.message,
|
error: emailError.message,
|
||||||
|
stack: emailError.stack,
|
||||||
userId,
|
userId,
|
||||||
addressId,
|
addressId,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const EmailClient = require("../core/EmailClient");
|
const EmailClient = require("../core/EmailClient");
|
||||||
const TemplateManager = require("../core/TemplateManager");
|
const TemplateManager = require("../core/TemplateManager");
|
||||||
|
const logger = require("../../../utils/logger");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RentalFlowEmailService handles rental lifecycle flow emails
|
* RentalFlowEmailService handles rental lifecycle flow emails
|
||||||
@@ -997,10 +998,12 @@ class RentalFlowEmailService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
console.error(
|
logger.error("Failed to send rental completion email to renter", {
|
||||||
`Failed to send rental completion email to renter (${renter.email}):`,
|
error: emailError.message,
|
||||||
emailError.message
|
stack: emailError.stack,
|
||||||
);
|
renterEmail: renter.email,
|
||||||
|
rentalId: rental.id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare owner email
|
// Prepare owner email
|
||||||
@@ -1114,13 +1117,19 @@ class RentalFlowEmailService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
console.error(
|
logger.error("Failed to send rental completion email to owner", {
|
||||||
`Failed to send rental completion email to owner (${owner.email}):`,
|
error: emailError.message,
|
||||||
emailError.message
|
stack: emailError.stack,
|
||||||
);
|
ownerEmail: owner.email,
|
||||||
|
rentalId: rental.id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending rental completion emails:", error);
|
logger.error("Error sending rental completion emails", {
|
||||||
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
|
rentalId: rental?.id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const { Rental, User, Item } = require("../models");
|
const { Rental, User, Item } = require("../models");
|
||||||
const StripeService = require("./stripeService");
|
const StripeService = require("./stripeService");
|
||||||
const emailServices = require("./email");
|
const emailServices = require("./email");
|
||||||
|
const logger = require("../utils/logger");
|
||||||
const { Op } = require("sequelize");
|
const { Op } = require("sequelize");
|
||||||
|
|
||||||
class PayoutService {
|
class PayoutService {
|
||||||
@@ -78,15 +79,18 @@ class PayoutService {
|
|||||||
// Send payout notification email to owner
|
// Send payout notification email to owner
|
||||||
try {
|
try {
|
||||||
await emailServices.rentalFlow.sendPayoutReceivedEmail(rental.owner, rental);
|
await emailServices.rentalFlow.sendPayoutReceivedEmail(rental.owner, rental);
|
||||||
console.log(
|
logger.info("Payout notification email sent to owner", {
|
||||||
`Payout notification email sent to owner for rental ${rental.id}`
|
rentalId: rental.id,
|
||||||
);
|
ownerId: rental.ownerId
|
||||||
|
});
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
// Log error but don't fail the payout
|
// Log error but don't fail the payout
|
||||||
console.error(
|
logger.error("Failed to send payout notification email", {
|
||||||
`Failed to send payout notification email for rental ${rental.id}:`,
|
error: emailError.message,
|
||||||
emailError.message
|
stack: emailError.stack,
|
||||||
);
|
rentalId: rental.id,
|
||||||
|
ownerId: rental.ownerId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ const initializeMessageSocket = (io) => {
|
|||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
userId,
|
userId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -124,6 +125,7 @@ const initializeMessageSocket = (io) => {
|
|||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
userId,
|
userId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -170,6 +172,7 @@ const initializeMessageSocket = (io) => {
|
|||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
userId,
|
userId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -208,6 +211,7 @@ const initializeMessageSocket = (io) => {
|
|||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
userId,
|
userId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -243,6 +247,7 @@ const initializeMessageSocket = (io) => {
|
|||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
userId,
|
userId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -305,6 +310,7 @@ const emitNewMessage = (io, receiverId, messageData) => {
|
|||||||
receiverId,
|
receiverId,
|
||||||
messageId: messageData.id,
|
messageId: messageData.id,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -330,6 +336,7 @@ const emitMessageRead = (io, senderId, readData) => {
|
|||||||
senderId,
|
senderId,
|
||||||
messageId: readData.messageId,
|
messageId: readData.messageId,
|
||||||
error: error.message,
|
error: error.message,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,17 +49,29 @@ const logFormat = winston.format.combine(
|
|||||||
const { timestamp, level, message, stack, ...metadata } = info;
|
const { timestamp, level, message, stack, ...metadata } = info;
|
||||||
let output = `${timestamp} ${level}: ${message}`;
|
let output = `${timestamp} ${level}: ${message}`;
|
||||||
|
|
||||||
// Check for stack trace in the info object itself
|
// Include relevant metadata in console output
|
||||||
if (stack) {
|
const metaKeys = Object.keys(metadata).filter(key =>
|
||||||
output += `\n${stack}`;
|
!['splat', 'Symbol(level)', 'Symbol(message)'].includes(key) &&
|
||||||
}
|
!key.startsWith('Symbol')
|
||||||
|
);
|
||||||
|
|
||||||
// Check for Error objects in metadata
|
if (metaKeys.length > 0) {
|
||||||
Object.keys(metadata).forEach(key => {
|
const metaOutput = {};
|
||||||
|
metaKeys.forEach(key => {
|
||||||
|
// For Error objects, extract message and stack
|
||||||
if (metadata[key] && metadata[key].stack) {
|
if (metadata[key] && metadata[key].stack) {
|
||||||
output += `\n${key}: ${metadata[key].message}\n${metadata[key].stack}`;
|
metaOutput[key] = { message: metadata[key].message, stack: metadata[key].stack };
|
||||||
|
} else {
|
||||||
|
metaOutput[key] = metadata[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
output += ` ${JSON.stringify(metaOutput, null, 2)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for stack trace in the info object itself
|
||||||
|
if (stack) {
|
||||||
|
output += `\nStack: ${stack}`;
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
|
|
||||||
// Focus the first input element when modal opens
|
// Focus the first input element when modal opens
|
||||||
if (modalRef.current) {
|
if (modalRef.current) {
|
||||||
const firstInput = modalRef.current.querySelector<HTMLElement>('input');
|
const firstInput = modalRef.current.querySelector<HTMLElement>("input");
|
||||||
firstInput?.focus();
|
firstInput?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,11 +96,12 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
const handleGoogleLogin = () => {
|
const handleGoogleLogin = () => {
|
||||||
const clientId = process.env.REACT_APP_GOOGLE_CLIENT_ID;
|
const clientId = process.env.REACT_APP_GOOGLE_CLIENT_ID;
|
||||||
const redirectUri = `${window.location.origin}/auth/google/callback`;
|
const redirectUri = `${window.location.origin}/auth/google/callback`;
|
||||||
const scope = 'openid email profile';
|
const scope = "openid email profile";
|
||||||
const responseType = 'code';
|
const responseType = "code";
|
||||||
|
|
||||||
const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
|
const googleAuthUrl =
|
||||||
`client_id=${encodeURIComponent(clientId || '')}` +
|
`https://accounts.google.com/o/oauth2/v2/auth?` +
|
||||||
|
`client_id=${encodeURIComponent(clientId || "")}` +
|
||||||
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
|
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
|
||||||
`&response_type=${responseType}` +
|
`&response_type=${responseType}` +
|
||||||
`&scope=${encodeURIComponent(scope)}` +
|
`&scope=${encodeURIComponent(scope)}` +
|
||||||
@@ -158,13 +159,14 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
// Show first specific validation error if available, otherwise generic error
|
// Show first specific validation error if available, otherwise generic error
|
||||||
const details = err.response?.data?.details;
|
const details = err.response?.data?.details;
|
||||||
const specificError = details?.[0]?.message;
|
const specificError = details?.[0]?.message;
|
||||||
setError(specificError || err.response?.data?.error || "An error occurred");
|
setError(
|
||||||
|
specificError || err.response?.data?.error || "An error occurred"
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (!show && !showForgotPassword && !showVerificationModal) return null;
|
if (!show && !showForgotPassword && !showVerificationModal) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -206,9 +208,7 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-body px-4 pb-4">
|
<div className="modal-body px-4 pb-4">
|
||||||
<h4 className="text-center mb-2">
|
<h4 className="text-center mb-2">Welcome to Village Share</h4>
|
||||||
Welcome to Village Share
|
|
||||||
</h4>
|
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="alert alert-danger" role="alert">
|
<div className="alert alert-danger" role="alert">
|
||||||
@@ -250,7 +250,6 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
className="form-control"
|
className="form-control"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
placeholder="name@example.com"
|
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -263,13 +262,18 @@ const AuthModal: React.FC<AuthModalProps> = ({
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
{mode === "signup" && (
|
{mode === "signup" && (
|
||||||
<div style={{ marginTop: '-0.75rem', marginBottom: '1rem' }}>
|
<div
|
||||||
|
style={{ marginTop: "-0.75rem", marginBottom: "1rem" }}
|
||||||
|
>
|
||||||
<PasswordStrengthMeter password={password} />
|
<PasswordStrengthMeter password={password} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{mode === "login" && (
|
{mode === "login" && (
|
||||||
<div className="text-end mb-3" style={{ marginTop: '-0.5rem' }}>
|
<div
|
||||||
|
className="text-end mb-3"
|
||||||
|
style={{ marginTop: "-0.5rem" }}
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
href="#"
|
href="#"
|
||||||
className="text-primary text-decoration-none small"
|
className="text-primary text-decoration-none small"
|
||||||
|
|||||||
Reference in New Issue
Block a user