Return 400 instead of 500 when deleting or showing something where the id is not an int
the build failed Details

This commit is contained in:
kolaente 2018-01-29 16:04:20 +01:00 committed by kolaente
parent 989ab530dd
commit 56a3215147
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
6 changed files with 8 additions and 5 deletions

View File

@ -18,7 +18,7 @@ func AuthorShow(c echo.Context) error {
// Make int
authorID, err := strconv.ParseInt(author, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting author infos."})
return c.JSON(http.StatusBadRequest, models.Message{"Author ID is invalid."})
}
// Get Author Infos

View File

@ -17,6 +17,9 @@ func BookShow(c echo.Context) error {
// Make int
bookID, err := strconv.ParseInt(book, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Book ID is invalid."})
}
// Get book infos
bookInfo, exists, err := models.GetBookByID(bookID)

View File

@ -18,7 +18,7 @@ func ItemShow(c echo.Context) error {
// Make int
itemID, err := strconv.ParseInt(item, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting item infos."})
return c.JSON(http.StatusBadRequest, models.Message{"Item ID is invalid."})
}
// Get item Infos

View File

@ -18,7 +18,7 @@ func PublisherShow(c echo.Context) error {
// Make int
publisherID, err := strconv.ParseInt(publisher, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher infos."})
return c.JSON(http.StatusBadRequest, models.Message{"Publisher ID is invalid."})
}
// Get Publisher Infos

View File

@ -24,7 +24,7 @@ func UserShow(c echo.Context) error {
// Make int
userID, err := strconv.ParseInt(user, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
return c.JSON(http.StatusBadRequest, models.Message{"User ID is invalid."})
}
// Get User Infos

View File

@ -25,7 +25,7 @@ func UserChangePassword(c echo.Context) error {
// Make int
userID, err := strconv.ParseInt(user, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
return c.JSON(http.StatusBadRequest, models.Message{"User ID is invalid."})
}
// Check if the user is admin or itself