Modified http status code on error

This commit is contained in:
konrad 2018-01-24 13:15:28 +01:00 committed by kolaente
parent dec5db7649
commit c8da860eab
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
7 changed files with 7 additions and 9 deletions

View File

@ -35,7 +35,7 @@ func AuthorDelete(c echo.Context) error {
if err != nil {
if models.IsErrIDCannotBeZero(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete author."})
}

View File

@ -63,7 +63,7 @@ func AuthorAddOrUpdate(c echo.Context) error {
if err != nil {
if models.IsErrAuthorCannotBeEmpty(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
}

View File

@ -35,7 +35,7 @@ func BookDelete(c echo.Context) error {
if err != nil {
if models.IsErrIDCannotBeZero(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete book."})
}

View File

@ -7,7 +7,6 @@ import (
"net/http"
"strconv"
"strings"
"fmt"
)
// BookAddOrUpdate is the handler to add a book
@ -63,9 +62,8 @@ func BookAddOrUpdate(c echo.Context) error {
newBook, err := models.AddOrUpdateBook(*datBook)
if err != nil {
fmt.Println(err)
if models.IsErrAuthorCannotBeEmpty(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0."})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0."})
}
if models.IsErrBookTitleCannotBeEmpty(err) {

View File

@ -35,7 +35,7 @@ func ItemDelete(c echo.Context) error {
if err != nil {
if models.IsErrIDCannotBeZero(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete item."})
}

View File

@ -35,7 +35,7 @@ func PublisherDelete(c echo.Context) error {
if err != nil {
if models.IsErrIDCannotBeZero(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete publisher."})
}

View File

@ -40,7 +40,7 @@ func UserDelete(c echo.Context) error {
if err != nil {
if models.IsErrIDCannotBeZero(err) {
return c.JSON(http.StatusInternalServerError, models.Message{"Id cannot be 0"})
return c.JSON(http.StatusBadRequest, models.Message{"Id cannot be 0"})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete user."})
}