fix(arayüz): sunucuya ulaşılamadığında açıklayıcı hata mesajı

- Vekil 502/503/504 döndüğünde "Beklenmeyen hata" yerine "Sunucu şu an yanıt vermiyor"
- Yerel geliştirmede backend'in kapalı kalması durumu MEMORY'ye not edildi

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 02:05:31 +03:00
parent feb2e1d16c
commit 33f64a0459
3 changed files with 16 additions and 1 deletions
+10 -1
View File
@@ -50,10 +50,19 @@ describe('api', () => {
expect(err.isUnauthorized).toBe(true)
})
it('JSON olmayan hata (ör. proxy 502) → genel Türkçe mesaj', async () => {
it('backend kapalı (vekil 502/503/504) → "sunucu yanıt vermiyor"', async () => {
globalThis.fetch = vi.fn().mockResolvedValue(new Response('Bad Gateway', { status: 502 }))
await expect(api.get('/health')).rejects.toMatchObject({
status: 502,
code: 'unavailable',
message: 'Sunucu şu an yanıt vermiyor. Birkaç saniye sonra tekrar deneyin.',
})
})
it('JSON olmayan diğer hata → genel Türkçe mesaj', async () => {
globalThis.fetch = vi.fn().mockResolvedValue(new Response('oops', { status: 500 }))
await expect(api.get('/health')).rejects.toMatchObject({
status: 500,
message: 'Beklenmeyen bir hata oluştu, lütfen tekrar deneyin.',
})
})
+5
View File
@@ -26,6 +26,8 @@ export class ApiError extends Error {
const NETWORK_MESSAGE = 'Sunucuya ulaşılamadı. İnternet bağlantınızı kontrol edip tekrar deneyin.'
const UNKNOWN_MESSAGE = 'Beklenmeyen bir hata oluştu, lütfen tekrar deneyin.'
/** Vekil (Vite / Traefik) backend'e ulaşamadı: yeniden başlıyor, güncelleniyor ya da kapalı */
const UNAVAILABLE_MESSAGE = 'Sunucu şu an yanıt vermiyor. Birkaç saniye sonra tekrar deneyin.'
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
@@ -48,6 +50,9 @@ async function request<T>(method: Method, path: string, body?: unknown): Promise
if (!res.ok) {
const detail = (data as Partial<ApiErrorBody> | null)?.error
if (!detail && [502, 503, 504].includes(res.status)) {
throw new ApiError(res.status, 'unavailable', UNAVAILABLE_MESSAGE)
}
throw new ApiError(res.status, detail?.code ?? 'unknown', detail?.message ?? UNKNOWN_MESSAGE)
}
return data as T