UNPKG

api-stds

Version:

Standardized API response and error handling toolkit with async handler, requestId, logging, and configurable formats.

13 lines (12 loc) 523 B
import { successResponse, errorResponse } from "../core/responses.js"; import { getConfig } from "../config/config.js"; export function standardize(customConfig) { const config = { ...getConfig(), ...customConfig }; return (req, res, next) => { res.success = (data, meta) => successResponse(res, data, meta); res.error = (code, message, details = {}, meta) => { return errorResponse(res, code, message || config.errors.defaultMessage, details, meta); }; next(); }; }