fix: 저장된 추가 이미지를 다시 읽지 못하면 빈 파일을 올리지 않고 사유를 알린다
이미지 파일은 서버 디스크에만 있고 DB 행은 공유되므로, dev에서 올린 이미지를 로컬 백엔드로 붙어 다시 읽으면 200에 빈 본문이 온다(백엔드가 없는 파일에 404 대신 빈 200을 준다 — 보고함). 그 0KB 파일이 묶음 재업로드에 섞여 500이 났다. 빈 본문은 실패로 다뤄 안내하고, 존재 확인도 content-length 0을 없는 것으로 센다. Co-Authored-By: Claude Opus 5
@170e52570dc43aa7af7152d024c094316d2f39f7
--- app/(protected)/(basic)/system/merchant-details/_actions.ts
+++ app/(protected)/(basic)/system/merchant-details/_actions.ts
... | ... | @@ -154,10 +154,13 @@ |
| 154 | 154 |
throw new InputError(INVALID_REQUEST_MESSAGE); |
| 155 | 155 |
} |
| 156 | 156 |
const response = await fetch(url, { cache: 'no-store' });
|
| 157 |
- if (!response.ok) {
|
|
| 158 |
- throw new InputError('저장된 이미지를 다시 읽지 못했습니다. 잠시 후 다시 시도해 주세요.');
|
|
| 157 |
+ const blob = response.ok ? await response.blob() : null; |
|
| 158 |
+ // 파일이 없어도 백엔드가 200에 빈 본문으로 답한다(보고함) — 빈 파일을 다시 올리면 500이 난다. |
|
| 159 |
+ if (!blob || blob.size === 0) {
|
|
| 160 |
+ throw new InputError( |
|
| 161 |
+ `저장된 추가 이미지 ${fileSn}번을 다시 읽지 못했습니다. 이 서버에 파일이 없을 수 있으니 이미지를 다시 올려 주세요.`
|
|
| 162 |
+ ); |
|
| 159 | 163 |
} |
| 160 |
- const blob = await response.blob(); |
|
| 161 | 164 |
const extension = blob.type.split('/')[1] || 'jpg';
|
| 162 | 165 |
return new File([blob], `image-${fileSn}.${extension}`, { type: blob.type });
|
| 163 | 166 |
} |
--- lib/data/repositories/merchant-detail-repository.ts
+++ lib/data/repositories/merchant-detail-repository.ts
... | ... | @@ -159,7 +159,9 @@ |
| 159 | 159 |
{ method: 'GET', timeout: PROBE_TIMEOUT_MS },
|
| 160 | 160 |
(response) => {
|
| 161 | 161 |
response.destroy(); |
| 162 |
- resolve((response.statusCode ?? 500) < 400); |
|
| 162 |
+ // 파일이 없어도 200에 빈 본문으로 답하는 서버가 있다(보고함) — 빈 것은 없는 것으로 본다. |
|
| 163 |
+ const isEmpty = response.headers['content-length'] === '0'; |
|
| 164 |
+ resolve((response.statusCode ?? 500) < 400 && !isEmpty); |
|
| 163 | 165 |
} |
| 164 | 166 |
); |
| 165 | 167 |
request.on('timeout', () => {
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?