261020_03_FIX: 요청 실패 시 원본 IOException 보존 기록

This commit is contained in:
2026-10-20 16:19:44 +09:00
parent 8f9dda7be1
commit 64d830fe67
2 changed files with 28 additions and 5 deletions

View File

@@ -128,7 +128,10 @@ public class ListAsyncDownloadService {
context.progress("FILE_READY", null, observer.values(true));
} catch (IOException failure) {
discard(result, failure);
throw BusinessException.internalError("LIST_DOWNLOAD_FAILED", "다운로드 파일 생성 중 오류가 발생했습니다.");
var wrapped = BusinessException.internalError("LIST_DOWNLOAD_FAILED", "다운로드 파일 생성 중 오류가 발생했습니다.");
// BusinessException has no public cause-aware factory and initializes its cause to null.
wrapped.addSuppressed(failure);
throw wrapped;
} catch (RuntimeException failure) {
discard(result, failure);
throw failure;

View File

@@ -11,6 +11,7 @@ import com.kri.contact.server.dto.list.async.ListAsyncResultFileDto;
import com.kri.contact.server.persistence.entity.TListAsyncJobEntity;
import com.kri.contact.server.service.file.ListAsyncResultFileService;
import jakarta.annotation.PreDestroy;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -234,9 +235,22 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
private static Map<String, Object> failureDetails(Throwable failure) {
var causes = new ArrayList<Map<String, Object>>();
var seen = Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
Throwable current = failure;
while (current != null && causes.size() < 8 && seen.add(current)) {
record PendingFailure(Throwable exception, String relation, int parentIndex) {}
var pending = new ArrayDeque<PendingFailure>();
pending.add(new PendingFailure(failure, "root", -1));
boolean truncated = false;
while (!pending.isEmpty() && causes.size() < 8) {
var entry = pending.removeFirst();
Throwable current = entry.exception();
if (!seen.add(current)) {
truncated = true;
continue;
}
var detail = new LinkedHashMap<String, Object>();
if (entry.parentIndex() >= 0) {
detail.put("relation", entry.relation());
detail.put("parentIndex", entry.parentIndex());
}
detail.put("exceptionType", current.getClass().getName());
if (current instanceof BusinessException business) {
String code = business.getCode();
@@ -251,10 +265,16 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
detail.put("stackTrace", Arrays.stream(current.getStackTrace()).limit(80)
.map(frame -> frame.getClassName() + "." + frame.getMethodName() + ":" + frame.getLineNumber())
.toList());
int parentIndex = causes.size();
causes.add(detail);
current = current.getCause();
if (current.getCause() != null) {
pending.add(new PendingFailure(current.getCause(), "cause", parentIndex));
}
for (Throwable suppressed : current.getSuppressed()) {
pending.add(new PendingFailure(suppressed, "suppressed", parentIndex));
}
}
return Map.of("causes", causes, "truncated", current != null);
return Map.of("causes", causes, "truncated", truncated || !pending.isEmpty());
}
private final class JobTask implements Runnable {