Added helper function to get logger
This commit is contained in:
parent
1c90eb2253
commit
b4a943dba1
|
@ -18,7 +18,6 @@ package handler
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
"github.com/op/go-logging"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Check rights
|
// Check rights
|
||||||
if !currentStruct.CanCreate(currentAuth) {
|
if !currentStruct.CanCreate(currentAuth) {
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Noticef("Tried to create while not having the rights for it", currentAuth)
|
getLogger(ctx).Noticef("Tried to create while not having the rights for it", currentAuth)
|
||||||
return echo.NewHTTPError(http.StatusForbidden)
|
return echo.NewHTTPError(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
if !currentStruct.CanDelete(currentAuth) {
|
if !currentStruct.CanDelete(currentAuth) {
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Noticef("Tried to delete while not having the rights for it", currentAuth)
|
getLogger(ctx).Noticef("Tried to delete while not having the rights for it", currentAuth)
|
||||||
return echo.NewHTTPError(http.StatusForbidden)
|
return echo.NewHTTPError(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,11 @@ func HandleHTTPError(err error, ctx echo.Context) *echo.HTTPError {
|
||||||
errDetails := a.HTTPError()
|
errDetails := a.HTTPError()
|
||||||
return echo.NewHTTPError(errDetails.HTTPCode, errDetails)
|
return echo.NewHTTPError(errDetails.HTTPCode, errDetails)
|
||||||
}
|
}
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Error(err.Error())
|
getLogger(ctx).Error(err.Error())
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to get the logger
|
||||||
|
func getLogger(ctx echo.Context) *logging.Logger {
|
||||||
|
return ctx.Get("LoggingProvider").(*logging.Logger)
|
||||||
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||||
}
|
}
|
||||||
pageNumber, err := strconv.Atoi(page)
|
pageNumber, err := strconv.Atoi(page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Error(err.Error())
|
getLogger(ctx).Error(err.Error())
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
|
||||||
}
|
}
|
||||||
if pageNumber < 0 {
|
if pageNumber < 0 {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||||
}
|
}
|
||||||
if !currentStruct.CanRead(currentAuth) {
|
if !currentStruct.CanRead(currentAuth) {
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Noticef("Tried to read one while not having the rights for it", currentAuth)
|
getLogger(ctx).Noticef("Tried to read one while not having the rights for it", currentAuth)
|
||||||
return echo.NewHTTPError(http.StatusForbidden, "You don't have the right to see this")
|
return echo.NewHTTPError(http.StatusForbidden, "You don't have the right to see this")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||||
}
|
}
|
||||||
if !currentStruct.CanUpdate(currentAuth) {
|
if !currentStruct.CanUpdate(currentAuth) {
|
||||||
ctx.Get("LoggingProvider").(*logging.Logger).Noticef("Tried to update while not having the rights for it", currentAuth)
|
getLogger(ctx).Noticef("Tried to update while not having the rights for it", currentAuth)
|
||||||
return echo.NewHTTPError(http.StatusForbidden)
|
return echo.NewHTTPError(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue