fix contrib form
This commit is contained in:
@@ -175,17 +175,6 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
const errorMessages = error.errors.map(err =>
|
||||
`${err.path.join('.')}: ${err.message}`
|
||||
);
|
||||
// BEFORE: Manual validation error response (7 lines)
|
||||
// return new Response(JSON.stringify({
|
||||
// success: false,
|
||||
// error: 'Validation failed',
|
||||
// details: errorMessages
|
||||
// }), {
|
||||
// status: 400,
|
||||
// headers: { 'Content-Type': 'application/json' }
|
||||
// });
|
||||
|
||||
// AFTER: Single line with consolidated helper
|
||||
return apiError.validation('Validation failed', errorMessages);
|
||||
}
|
||||
|
||||
@@ -208,46 +197,35 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Submit contribution via Git
|
||||
const gitManager = new GitContributionManager();
|
||||
const result = await gitManager.submitContribution(contributionData);
|
||||
// CRITICAL FIX: Enhanced error handling for Git operations
|
||||
try {
|
||||
const gitManager = new GitContributionManager();
|
||||
const result = await gitManager.submitContribution(contributionData);
|
||||
|
||||
if (result.success) {
|
||||
// Log successful contribution
|
||||
console.log(`[CONTRIBUTION] ${validatedData.action} "${validatedData.tool.name}" by ${userEmail} - PR: ${result.prUrl}`);
|
||||
if (result.success) {
|
||||
// Log successful contribution
|
||||
console.log(`[CONTRIBUTION SUCCESS] ${validatedData.action} "${validatedData.tool.name}" by ${userEmail} - PR: ${result.prUrl}`);
|
||||
|
||||
// ENSURE proper success response
|
||||
return apiResponse.created({
|
||||
success: true,
|
||||
message: result.message,
|
||||
prUrl: result.prUrl,
|
||||
branchName: result.branchName
|
||||
});
|
||||
} else {
|
||||
// Log failed contribution
|
||||
console.error(`[CONTRIBUTION FAILED] ${validatedData.action} "${validatedData.tool.name}" by ${userEmail}: ${result.message}`);
|
||||
|
||||
return apiServerError.internal(`Contribution failed: ${result.message}`);
|
||||
}
|
||||
} catch (gitError) {
|
||||
// CRITICAL: Handle Git operation errors properly
|
||||
console.error(`[GIT ERROR] ${validatedData.action} "${validatedData.tool.name}" by ${userEmail}:`, gitError);
|
||||
|
||||
// BEFORE: Manual success response (7 lines)
|
||||
// return new Response(JSON.stringify({
|
||||
// success: true,
|
||||
// message: result.message,
|
||||
// prUrl: result.prUrl,
|
||||
// branchName: result.branchName
|
||||
// }), {
|
||||
// status: 200,
|
||||
// headers: { 'Content-Type': 'application/json' }
|
||||
// });
|
||||
|
||||
// AFTER: Single line with consolidated helper
|
||||
return apiResponse.created({
|
||||
message: result.message,
|
||||
prUrl: result.prUrl,
|
||||
branchName: result.branchName
|
||||
});
|
||||
} else {
|
||||
// Log failed contribution
|
||||
console.error(`[CONTRIBUTION FAILED] ${validatedData.action} "${validatedData.tool.name}" by ${userEmail}: ${result.message}`);
|
||||
|
||||
// BEFORE: Manual error response (7 lines)
|
||||
// return new Response(JSON.stringify({
|
||||
// success: false,
|
||||
// error: result.message
|
||||
// }), {
|
||||
// status: 500,
|
||||
// headers: { 'Content-Type': 'application/json' }
|
||||
// });
|
||||
|
||||
// AFTER: Single line with consolidated helper
|
||||
return apiServerError.internal(`Contribution failed: ${result.message}`);
|
||||
// Return proper error response
|
||||
const errorMessage = gitError instanceof Error ? gitError.message : 'Git operation failed';
|
||||
return apiServerError.internal(`Git operation failed: ${errorMessage}`);
|
||||
}
|
||||
|
||||
}, 'Contribution processing failed');
|
||||
|
||||
Reference in New Issue
Block a user