Modified http status code on error
This commit is contained in:
parent
dec5db7649
commit
c8da860eab
|
@ -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."})
|
||||
}
|
||||
|
|
|
@ -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"})
|
||||
}
|
||||
|
|
|
@ -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."})
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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."})
|
||||
}
|
||||
|
|
|
@ -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."})
|
||||
}
|
||||
|
|
|
@ -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."})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue