23 lines
633 B
JavaScript
23 lines
633 B
JavaScript
import { ApiError, errorEnvelope } from "../errors";
|
|
export function successResponse(req, data) {
|
|
return {
|
|
data,
|
|
request_id: req.requestId,
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
}
|
|
export function handleErrors(err, req, res, _next) {
|
|
if (err instanceof ApiError) {
|
|
res.status(err.statusCode).json(errorEnvelope({
|
|
...err
|
|
}, req.requestId));
|
|
return;
|
|
}
|
|
res.status(500).json({
|
|
code: "INTERNAL_ERROR",
|
|
message: err.message || "Unexpected server error",
|
|
request_id: req.requestId,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
}
|