-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
priority: lowP3 - Do eventually, polishP3 - Do eventually, polishrefactorCode refactoringCode refactoring
Description
Problem
Error responses are inconsistent across handlers:
// handlers/resource.js
reply.code(404).send({ error: 'Not Found' });
// handlers/container.js
reply.code(400).send({ error: 'Slug header too long' });
// Some include message field, some don't
reply.code(403).send({ error: 'Forbidden', message: 'Access denied' });
reply.code(404).send({ error: 'Not Found' }); // no message
// Some wrap in try/catch, some don'tIssues:
- Inconsistent error object shape (
errorvserror+message) - Error strings not centralized (typo risk)
- No standard HTTP status code mapping
- Mixed try/catch patterns
Proposed Solution
Create error response utility:
// src/utils/errors.js
export const ErrorCodes = {
NOT_FOUND: { code: 404, error: 'Not Found' },
FORBIDDEN: { code: 403, error: 'Forbidden' },
UNAUTHORIZED: { code: 401, error: 'Unauthorized' },
BAD_REQUEST: { code: 400, error: 'Bad Request' },
CONFLICT: { code: 409, error: 'Conflict' },
PAYLOAD_TOO_LARGE: { code: 413, error: 'Payload Too Large' },
UNSUPPORTED_MEDIA: { code: 415, error: 'Unsupported Media Type' },
INTERNAL_ERROR: { code: 500, error: 'Internal Server Error' }
};
export function sendError(reply, errorType, message = '') {
const { code, error } = errorType;
return reply.code(code).send({ error, message });
}Usage:
import { sendError, ErrorCodes } from '../utils/errors.js';
// Before
reply.code(404).send({ error: 'Not Found' });
// After
sendError(reply, ErrorCodes.NOT_FOUND, 'Resource does not exist');Benefits
- Consistent error shape across all handlers
- Centralized error strings (no typos)
- Easy to add logging/metrics
- Simpler handler code
Files Affected
- Create:
src/utils/errors.js - Modify:
src/handlers/resource.js - Modify:
src/handlers/container.js - Modify:
src/handlers/git.js - Modify:
src/auth/middleware.js
Priority
P3 - Low priority polish
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priority: lowP3 - Do eventually, polishP3 - Do eventually, polishrefactorCode refactoringCode refactoring