When designing and implementing web interfaces to ensure they are usable by everyone.
The English summary is being prepared. Showing the original description.
When designing how a system recovers from and reports failures.
The English summary is being prepared. Showing the original description.
See how to installReview the instructions the agent will receive before you install.
Uncaught exceptions crash servers. Leaked errors expose vulnerabilities. This skill creates a central, robust pipeline for capturing, categorizing, logging, and responding to failures without leaking sensitive data, ensuring system resilience and debugging capability.
try/catch blocksAppError class with statusCode, isOperational flag, and metadatacatch(e) {})throw "User not found" (throw Error objects always)catch(e) {} with no logging or action{ error: true } payloadtype, title, detail, statuscatch(e) {} blocks with no actionstatusCode, message, isOperational flag, and optional context❌ Anti-pattern (Silent catching, leaking details, wrong status):
app.get('/users/:id', async (req, res) => {
try {
const user = await db.query(`SELECT * FROM users WHERE id = ${req.params.id}`);
res.json(user);
} catch(e) {
// ANTI-PATTERN: silent catch
res.json({ status: 'error', message: e.message }); // ANTI-PATTERN: 200 OK
// ANTI-PATTERN: leaking SQL details
}
});
✅ Correct pattern (Centralized, sanitized, proper codes):
// 1. Define error class
class AppError extends Error {
constructor(statusCode, message, isOperational = true) {
super(message);
this.statusCode = statusCode;
this.isOperational = isOperational;
}
}
// 2. Route handler
app.get('/users/:id', async (req, res, next) => {
try {
const user = await db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);
if (!user) {
return next(new AppError(404, 'User not found'));
}
res.json(user);
} catch (err) {
next(err); // Pass to global handler
}
});
// 3. Global error middleware
app.use((err, req, res, next) => {
// Log with context
logger[err.isOperational ? 'warn' : 'error']({
message: err.message,
statusCode: err.statusCode,
stack: err.stack,
requestId: req.id,
userId: req.user?.id
});
// Crash on programmer error
if (!err.isOperational) {
process.exit(1);
}
// Sanitized response
res.status(err.statusCode || 500).json({
type: 'https://api.example.com/errors/app-error',
title: err.statusCode === 404 ? 'Not Found' : 'Server Error',
detail: err.isOperational ? err.message : 'Internal server error',
status: err.statusCode || 500
});
});
No reviews yet. Tell others what you thought.
No login needed. Share how it worked for you, ask a question, or note where it did not run.
No comments yet. Be the first to write one.
When designing and implementing web interfaces to ensure they are usable by everyone.
The English summary is being prepared. Showing the original description.
When creating or extending an HTTP API for client consumption.
The English summary is being prepared. Showing the original description.
When improving read performance and reducing database load.
The English summary is being prepared. Showing the original description.
When configuring automated build, test, and deployment workflows for a repository.
The English summary is being prepared. Showing the original description.
When asynchronously reviewing peer code before merging into the main branch.
The English summary is being prepared. Showing the original description.
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.
The English summary is being prepared. Showing the original description.