261008_01_ENH: 외부 API 및 bypass 원본 오류 응답 전파 기능 추가

This commit is contained in:
2026-10-08 10:58:29 +09:00
parent 16dc89ac92
commit 65e31079ac
15 changed files with 254 additions and 7 deletions

View File

@@ -0,0 +1,41 @@
package com.kri.common.feature.http;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** An upstream HTTP error whose response can be relayed without rewriting its body. */
public class ExternalApiResponseException extends RuntimeException {
private final int statusCode;
private final Map<String, List<String>> headers;
private final byte[] body;
public ExternalApiResponseException(int statusCode, Map<String, List<String>> headers, byte[] body) {
super("External API returned HTTP " + statusCode);
this.statusCode = statusCode;
Map<String, List<String>> copy = new LinkedHashMap<>();
if (headers != null) {
headers.forEach((name, values) -> {
if (name != null && values != null) {
copy.put(name, List.copyOf(values));
}
});
}
this.headers = Collections.unmodifiableMap(copy);
this.body = body == null ? new byte[0] : body.clone();
}
public int getStatusCode() {
return statusCode;
}
public Map<String, List<String>> getHeaders() {
return headers;
}
public byte[] getBody() {
return body.clone();
}
}