From b40ac615b3b6b4ac3ea5933b9b1c317498a3a59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Fri, 2 Oct 2026 15:38:47 +0300 Subject: [PATCH] fix(storage): map context deadline exceeded to unavailable error --- backend/internal/storage/postgres/errors.go | 7 +++++-- backend/internal/storage/redis/errors.go | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/internal/storage/postgres/errors.go b/backend/internal/storage/postgres/errors.go index a3a4de3..6386128 100644 --- a/backend/internal/storage/postgres/errors.go +++ b/backend/internal/storage/postgres/errors.go @@ -27,8 +27,11 @@ func mapError(err error) error { if errors.Is(err, pgx.ErrNoRows) { return err } - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return err + if errors.Is(err, context.DeadlineExceeded) { + return &domain.UnavailableError{Reason: "превышено время ожидания БД"} + } + if errors.Is(err, context.Canceled) { + return &domain.UnavailableError{Reason: "запрос отменён"} } return &domain.UnavailableError{Reason: err.Error()} } diff --git a/backend/internal/storage/redis/errors.go b/backend/internal/storage/redis/errors.go index c2cc435..55e3422 100644 --- a/backend/internal/storage/redis/errors.go +++ b/backend/internal/storage/redis/errors.go @@ -11,6 +11,8 @@ type coded interface { Code() domain.ErrorCode } +// mapError переводит ошибки драйвера в доменные. +// Любая недоступность redis (dial/read/write/context) → UnavailableError (503). func mapError(err error) error { if err == nil { return nil @@ -19,8 +21,11 @@ func mapError(err error) error { if errors.As(err, &c) { return err } - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return err + if errors.Is(err, context.DeadlineExceeded) { + return &domain.UnavailableError{Reason: "превышено время ожидания redis"} + } + if errors.Is(err, context.Canceled) { + return &domain.UnavailableError{Reason: "запрос отменён"} } return &domain.UnavailableError{Reason: err.Error()} }