Add logging across app and centralized error handling
This commit is contained in:
parent
3bbeab1199
commit
4c3f095109
10 changed files with 115 additions and 62 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package link
|
||||
|
||||
import (
|
||||
. "cgnolink/err"
|
||||
"encoding/json"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
|
@ -16,7 +15,7 @@ func redirectHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
|
||||
link, err := serv.GetById(linkId)
|
||||
if err != nil {
|
||||
return MapErrToHTTPErr(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Redirect(http.StatusSeeOther, link.RedirectURL.String())
|
||||
|
|
@ -36,7 +35,7 @@ func creationHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
serv := PgService{rep: PgRepository{pool: pool}}
|
||||
|
||||
if err = serv.Create(entity); err != nil {
|
||||
return MapErrToHTTPErr(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.NoContent(http.StatusCreated)
|
||||
|
|
@ -49,7 +48,7 @@ func retrievalByIdHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
|
||||
l, err := serv.GetById(linkId)
|
||||
if err != nil {
|
||||
return MapErrToHTTPErr(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, MapEntityToModel(l))
|
||||
|
|
@ -80,7 +79,7 @@ func allRetrievalHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
|
||||
links, err := serv.GetAll(limit, offset)
|
||||
if err != nil {
|
||||
return MapErrToHTTPErr(err)
|
||||
return err
|
||||
}
|
||||
|
||||
models := make([]ResourceModel, len(links))
|
||||
|
|
@ -97,7 +96,7 @@ func removalHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
serv := PgService{rep: PgRepository{pool: pool}}
|
||||
|
||||
if err := serv.DeleteById(linkId); err != nil {
|
||||
return MapErrToHTTPErr(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue