Action | Type | Resolved On |
|---|---|---|
| Create API response utility for consistent JSON responses | feature | - - - |
API routes currently have inconsistent error response formats. Some return structured JSON while others return plain text. Create a unified response utility in src/lib/api-response.ts.
JSON format (good):
return new Response(JSON.stringify({ error: "Owner is required" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
Plain text (inconsistent):
return new Response("Task is required", { status: 400 });
Create src/lib/api-response.ts:
export function successResponse(data?: object, message?: string): Response {
return new Response(
JSON.stringify({ success: true, data, message }),
{ status: 200, headers: { "Content-Type": "application/json" } }
);
}
export function errorResponse(message: string, status: number): Response {
return new Response(
JSON.stringify({ success: false, error: message }),
{ status, headers: { "Content-Type": "application/json" } }
);
}
export const badRequest = (msg: string) => errorResponse(msg, 400);
export const serverError = (msg: string) => errorResponse(msg, 500);
export const notFound = (msg: string) => errorResponse(msg, 404);
src/pages/api/new/goal.tssrc/pages/api/new/backlog.tssrc/pages/api/open/*.tssrc/pages/api/close/*.tssrc/pages/api/update/*.ts