Log errors with context to help debugging. Include timestamps, user IDs, and operation details.
catch (error) {
console.error({
message: error.message,
stack: error.stack,
userId: currentUser.id,
operation: "checkout",
timestamp: new Date().toISOString()
});
}
In production, send logs to a monitoring service.