feat: merge auth&tester
This commit is contained in:
parent
0a2dea6c23
commit
441af4c6a2
72 changed files with 4910 additions and 2378 deletions
|
@ -1,8 +1,11 @@
|
|||
package pkg
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/jackc/pgerrcode"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -35,3 +38,21 @@ func ToREST(err error) int {
|
|||
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
|
||||
func HandlePgErr(err error, op string) error {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgerrcode.IsIntegrityConstraintViolation(pgErr.Code) {
|
||||
return Wrap(ErrBadInput, err, op, pgErr.Message)
|
||||
}
|
||||
if pgerrcode.IsNoData(pgErr.Code) {
|
||||
return Wrap(ErrNotFound, err, op, pgErr.Message)
|
||||
}
|
||||
}
|
||||
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return Wrap(ErrNotFound, err, op, "no rows found")
|
||||
}
|
||||
|
||||
return Wrap(ErrUnhandled, err, op, "unexpected error")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue