fix(db): fix error handling in person get func

This commit is contained in:
Masahiko AMANO 2025-01-18 19:01:22 +03:00
parent e003bfd947
commit 0112484375

View File

@ -110,11 +110,13 @@ func PersonGet(ctx context.Context, user_id, person_id string) (person models.Pe
row := connPool.QueryRow(ctx, "SELECT id, name, COALESCE(sort_name, ''), COALESCE(TO_CHAR(birthdate, 'YYYY-MM-DD'), ''), COALESCE(TO_CHAR(deathdate, 'YYYY-MM-DD'), ''), COALESCE(info, '') FROM persons WHERE id=$1", person_id)
err = row.Scan(&person.ID, &person.Name, &person.SortName, &person.Birthdate, &person.Deathdate, &person.Deathdate)
if err != nil {
pgErr := err.(*pgconn.PgError)
if err == pgx.ErrNoRows {
err = fmt.Errorf("not found")
statusCode = http.StatusNotFound
} else if pgErr.Code == "22P02" || pgErr.Code == "22007" {
return
}
pgErr := err.(*pgconn.PgError)
if pgErr.Code == "22P02" || pgErr.Code == "22007" {
err = fmt.Errorf("%s", pgErr.Message)
statusCode = http.StatusBadRequest
} else {