refactor(api): rename database error handler function
This commit is contained in:
parent
adcc7d22c3
commit
82134a8cd2
@ -25,7 +25,7 @@ func userAuth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
user, err := db.UserAuth(context.Background(), credentials.Login, credentials.Password)
|
user, err := db.UserAuth(context.Background(), credentials.Login, credentials.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status, message := HandlePgError(err)
|
status, message := HandleDBError(err)
|
||||||
c.JSON(status, gin.H{"error": message})
|
c.JSON(status, gin.H{"error": message})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func quotesGet(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
quotes, err := db.QuotesGet(c, user_id, filter, sort, int(limit), int(offset))
|
quotes, err := db.QuotesGet(c, user_id, filter, sort, int(limit), int(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status, message := HandlePgError(err)
|
status, message := HandleDBError(err)
|
||||||
c.JSON(status, gin.H{"error": message})
|
c.JSON(status, gin.H{"error": message})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgconn"
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandlePgError(err error) (int, string) {
|
func HandleDBError(err error) (int, string) {
|
||||||
pgErr, ok := err.(*pgconn.PgError)
|
pgErr, ok := err.(*pgconn.PgError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 500, err.Error()
|
return 500, err.Error()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user