2024-08-17 12:23:35 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-08-20 11:18:23 +00:00
|
|
|
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
2024-08-17 12:23:35 +00:00
|
|
|
"github.com/jackc/pgerrcode"
|
|
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
|
|
)
|
|
|
|
|
2024-08-20 11:18:23 +00:00
|
|
|
func handlePgErr(err error) error {
|
2024-08-17 12:23:35 +00:00
|
|
|
var pgErr *pgconn.PgError
|
|
|
|
if !errors.As(err, &pgErr) {
|
2024-08-20 11:18:23 +00:00
|
|
|
//storage.logger.DPanic("unexpected error from postgres", zap.String("err", err.Error()))
|
2024-08-17 12:23:35 +00:00
|
|
|
return lib.ErrUnexpected
|
|
|
|
}
|
|
|
|
if pgerrcode.IsIntegrityConstraintViolation(pgErr.Code) {
|
|
|
|
return errors.New("unique key violation") // FIXME
|
|
|
|
}
|
2024-08-20 11:18:23 +00:00
|
|
|
//storage.logger.DPanic("unexpected internal error from postgres", zap.String("err", err.Error()))
|
2024-08-17 12:23:35 +00:00
|
|
|
return lib.ErrInternal
|
|
|
|
}
|