23 lines
700 B
Go
23 lines
700 B
Go
package repository
|
|
|
|
import (
|
|
"errors"
|
|
"git.sch9.ru/new_gate/ms-tester/pkg/utils"
|
|
"github.com/jackc/pgerrcode"
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
)
|
|
|
|
func handlePgErr(err error) error {
|
|
var pgErr *pgconn.PgError
|
|
if !errors.As(err, &pgErr) {
|
|
return utils.StorageError(err, utils.ErrUnknown, "unexpected error from postgres")
|
|
}
|
|
if pgerrcode.IsIntegrityConstraintViolation(pgErr.Code) {
|
|
// TODO: probably should specify which constraint
|
|
return utils.StorageError(err, utils.ErrConflict, pgErr.Message)
|
|
}
|
|
if pgerrcode.IsNoData(pgErr.Code) {
|
|
return utils.StorageError(err, utils.ErrNotFound, pgErr.Message)
|
|
}
|
|
return utils.StorageError(err, utils.ErrUnimplemented, "unimplemented error")
|
|
}
|