summaryrefslogtreecommitdiff
path: root/lib/soap/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/soap/utils.ts')
-rw-r--r--lib/soap/utils.ts26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/soap/utils.ts b/lib/soap/utils.ts
index 57e3b280..809dd46d 100644
--- a/lib/soap/utils.ts
+++ b/lib/soap/utils.ts
@@ -466,6 +466,7 @@ export async function cleanupOldSoapLogs(): Promise<void> {
* @param interfaceName 인터페이스명
* @param requestData 요청 데이터
* @param processor 실제 비즈니스 로직 함수
+ * @param extractResponse 응답 데이터 추출 함수 (선택사항)
* @returns 처리 결과
*/
export async function withSoapLogging<T>(
@@ -473,7 +474,8 @@ export async function withSoapLogging<T>(
system: string,
interfaceName: string,
requestData: string,
- processor: () => Promise<T>
+ processor: () => Promise<T>,
+ extractResponse?: (result: T) => string | undefined
): Promise<T> {
let logId: number | null = null;
@@ -484,10 +486,16 @@ export async function withSoapLogging<T>(
// 2. 실제 처리 실행
const result = await processor();
- // 3. 성공 로그 완료
- await completeSoapLog(logId, true);
+ // 3. 응답 데이터 추출 (제공된 경우)
+ let responseData: string | undefined;
+ if (extractResponse) {
+ responseData = extractResponse(result);
+ }
+
+ // 4. 성공 로그 완료 (응답 데이터 포함)
+ await completeSoapLog(logId, true, responseData);
- // 4. 로그 정리 (백그라운드)
+ // 5. 로그 정리 (백그라운드)
cleanupOldSoapLogs().catch(error =>
console.error('백그라운드 로그 정리 실패:', error)
);
@@ -495,12 +503,18 @@ export async function withSoapLogging<T>(
return result;
} catch (error) {
- // 5. 실패 로그 완료
+ // 6. 실패 로그 완료
if (logId !== null) {
+ // 에러 객체에 응답 데이터가 포함되어 있는지 확인
+ let errorResponseData: string | undefined;
+ if (error && typeof error === 'object' && 'responseText' in error) {
+ errorResponseData = (error as { responseText?: string }).responseText;
+ }
+
await completeSoapLog(
logId,
false,
- undefined,
+ errorResponseData,
error instanceof Error ? error.message : 'Unknown error'
);
}