- Create src/utils/http.js - fetchT and HTTP helpers - Create src/utils/logging.js - Structured logging and error logging - Create src/utils/responses.js - Standard API responses - Create src/utils/async-handler.js - Async wrapper with error handling - Create src/utils/index.js - Consolidated exports Removes scattered helper functions from server.js
23 lines
410 B
JavaScript
23 lines
410 B
JavaScript
/**
|
|
* Response helpers - Standard API response formats
|
|
*/
|
|
|
|
/**
|
|
* Standard error response
|
|
*/
|
|
function errorResponse(res, statusCode, message, extras = {}) {
|
|
return res.status(statusCode).json({ success: false, error: message, ...extras });
|
|
}
|
|
|
|
/**
|
|
* Standard success response
|
|
*/
|
|
function ok(res, data = {}) {
|
|
return res.json({ success: true, ...data });
|
|
}
|
|
|
|
module.exports = {
|
|
errorResponse,
|
|
ok,
|
|
};
|