Проверка и завершение требований уровней «3» и «4»
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package apperr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
@@ -27,7 +31,21 @@ func (e *AppError) handlePostgres() {
|
||||
return
|
||||
}
|
||||
|
||||
var networkError net.Error
|
||||
var connectError *pgconn.ConnectError
|
||||
if errors.Is(e.err, context.DeadlineExceeded) || errors.Is(e.err, io.EOF) ||
|
||||
errors.Is(e.err, io.ErrUnexpectedEOF) || errors.As(e.err, &networkError) || errors.As(e.err, &connectError) {
|
||||
e.code = CodeServiceUnavailable
|
||||
e.msg = "database unavailable"
|
||||
return
|
||||
}
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](e.err); ok {
|
||||
if strings.HasPrefix(pgErr.Code, "08") || pgErr.Code == "57014" ||
|
||||
pgErr.Code == "57P01" || pgErr.Code == "57P02" || pgErr.Code == "57P03" || pgErr.Code == "53300" {
|
||||
e.code = CodeServiceUnavailable
|
||||
e.msg = "database unavailable"
|
||||
return
|
||||
}
|
||||
e.meta[PgErrorCode] = pgErr.Code
|
||||
e.code = CodeFromPostgres(pgErr.Code)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user