From backend-dev
Design or implement error handling patterns — custom error classes, error boundaries, API error responses
npx claudepluginhub silviaare95/xari-plugins --plugin backend-devThis skill uses the workspace's default tool permissions.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Designs, audits, and improves analytics tracking systems using Signal Quality Index for reliable, decision-ready data in marketing, product, and growth.
Enforces A/B test setup with gates for hypothesis locking, metrics definition, sample size calculation, assumptions checks, and execution readiness before implementation.
Design error handling for: $0 scope
Language/framework: $1 (default: TypeScript)
Audit current state — Read the existing error handling in the target scope. Identify:
catch (e) {} or catch (e) { console.log(e) })Design error hierarchy — Create a structured error system:
// Base application error
class AppError extends Error {
constructor(
message: string,
public code: string,
public statusCode: number = 500,
public isOperational: boolean = true
) {
super(message);
this.name = this.constructor.name;
}
}
// Specific errors
class ValidationError extends AppError {
constructor(message: string, public fields?: Record<string, string>) {
super(message, "VALIDATION_ERROR", 400);
}
}
class NotFoundError extends AppError {
constructor(resource: string, id?: string) {
super(
id ? `${resource} with id ${id} not found` : `${resource} not found`,
"NOT_FOUND",
404
);
}
}
class UnauthorizedError extends AppError {
constructor(message = "Authentication required") {
super(message, "UNAUTHORIZED", 401);
}
}
class ForbiddenError extends AppError {
constructor(message = "Insufficient permissions") {
super(message, "FORBIDDEN", 403);
}
}
Implement error handler — Based on scope:
API: Global error handler middleware that catches AppError subclasses and returns consistent JSON responses. Log unexpected errors, return generic messages.
Service: Translate external errors (Prisma, fetch, etc.) into AppError subclasses at service boundaries. Never let raw database errors reach the API layer.
Component (React): Error boundaries with fallback UI. useErrorHandler hook for async errors.
Add logging — Structured error logging:
warn levelerror level with stack traceProduce implementation code with: