Added helper function to get logger
This commit is contained in:
parent
1c90eb2253
commit
b4a943dba1
|
@ -18,7 +18,6 @@ package handler
|
|||
import (
|
||||
"code.vikunja.io/web"
|
||||
"github.com/labstack/echo"
|
||||
"github.com/op/go-logging"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -46,7 +45,7 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
|||
|
||||
// Check rights
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
|||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ func HandleHTTPError(err error, ctx echo.Context) *echo.HTTPError {
|
|||
errDetails := a.HTTPError()
|
||||
return echo.NewHTTPError(errDetails.HTTPCode, errDetails)
|
||||
}
|
||||
ctx.Get("LoggingProvider").(*logging.Logger).Error(err.Error())
|
||||
getLogger(ctx).Error(err.Error())
|
||||
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)
|
||||
if err != nil {
|
||||
ctx.Get("LoggingProvider").(*logging.Logger).Error(err.Error())
|
||||
getLogger(ctx).Error(err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
|
||||
}
|
||||
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.")
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
|||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user