fix: Enhance error handling and validation messages in form data operations

- Integrated `formatPgError` utility to provide user-friendly error messages based on PostgreSQL error codes during form data operations.
- Updated error responses in `saveFormData`, `saveFormDataEnhanced`, `updateFormData`, and `updateFormDataPartial` to include specific messages based on the company context.
- Improved error handling in the frontend components to display relevant error messages from the server response, ensuring users receive clear feedback on save operations.
- Enhanced the required field validation by incorporating NOT NULL metadata checks across various components, improving the accuracy of form submissions.

These changes improve the overall user experience by providing clearer error messages and ensuring that required fields are properly validated based on both manual settings and database constraints.
This commit is contained in:
kjs
2026-03-10 14:47:05 +09:00
parent 43523a0bba
commit 28ef7e1226
16 changed files with 180 additions and 86 deletions

View File

@@ -2,6 +2,7 @@ import { Response } from "express";
import { dynamicFormService } from "../services/dynamicFormService";
import { enhancedDynamicFormService } from "../services/enhancedDynamicFormService";
import { AuthenticatedRequest } from "../types/auth";
import { formatPgError } from "../utils/pgErrorUtil";
// 폼 데이터 저장 (기존 버전 - 레거시 지원)
export const saveFormData = async (
@@ -68,9 +69,12 @@ export const saveFormData = async (
});
} catch (error: any) {
console.error("❌ 폼 데이터 저장 실패:", error);
res.status(500).json({
const { companyCode } = req.user as any;
const friendlyMsg = await formatPgError(error, companyCode);
const statusCode = error.code?.startsWith("23") ? 400 : 500;
res.status(statusCode).json({
success: false,
message: error.message || "데이터 저장에 실패했습니다.",
message: friendlyMsg,
});
}
};
@@ -118,9 +122,12 @@ export const saveFormDataEnhanced = async (
res.json(result);
} catch (error: any) {
console.error("❌ 개선된 폼 데이터 저장 실패:", error);
res.status(500).json({
const { companyCode } = req.user as any;
const friendlyMsg = await formatPgError(error, companyCode);
const statusCode = error.code?.startsWith("23") ? 400 : 500;
res.status(statusCode).json({
success: false,
message: error.message || "데이터 저장에 실패했습니다.",
message: friendlyMsg,
});
}
};
@@ -163,9 +170,12 @@ export const updateFormData = async (
});
} catch (error: any) {
console.error("❌ 폼 데이터 업데이트 실패:", error);
res.status(500).json({
const { companyCode } = req.user as any;
const friendlyMsg = await formatPgError(error, companyCode);
const statusCode = error.code?.startsWith("23") ? 400 : 500;
res.status(statusCode).json({
success: false,
message: error.message || "데이터 업데이트에 실패했습니다.",
message: friendlyMsg,
});
}
};
@@ -216,9 +226,12 @@ export const updateFormDataPartial = async (
});
} catch (error: any) {
console.error("❌ 부분 업데이트 실패:", error);
res.status(500).json({
const { companyCode } = req.user as any;
const friendlyMsg = await formatPgError(error, companyCode);
const statusCode = error.code?.startsWith("23") ? 400 : 500;
res.status(statusCode).json({
success: false,
message: error.message || "부분 업데이트에 실패했습니다.",
message: friendlyMsg,
});
}
};