Improved error messages
the build failed
Details
the build failed
Details
This commit is contained in:
parent
d2476e061f
commit
224e795531
|
@ -50,11 +50,11 @@ func AuthorAddOrUpdate(c echo.Context) error {
|
||||||
if datAuthor.ID != 0 {
|
if datAuthor.ID != 0 {
|
||||||
_, exists, err := models.GetAuthorByID(datAuthor.ID)
|
_, exists, err := models.GetAuthorByID(datAuthor.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the author exists"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the author exists."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return c.JSON(http.StatusNotFound, models.Message{"The author does not exist"})
|
return c.JSON(http.StatusNotFound, models.Message{"The author does not exist."})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func AuthorAddOrUpdate(c echo.Context) error {
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Added or updated an author", newAuthor.ID, c)
|
err = models.LogAction("Added or updated an author", newAuthor.ID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, newAuthor)
|
return c.JSON(http.StatusOK, newAuthor)
|
||||||
|
|
|
@ -15,7 +15,7 @@ func AuthorsList(c echo.Context) error {
|
||||||
list, err := models.ListAuthors(search)
|
list, err := models.ListAuthors(search)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, list)
|
return c.JSON(http.StatusOK, list)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func BookShow(c echo.Context) error {
|
||||||
bookInfo, exists, err := models.GetBookByID(bookID)
|
bookInfo, exists, err := models.GetBookByID(bookID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get book infos"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get book infos."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it exists
|
// Check if it exists
|
||||||
|
|
|
@ -17,7 +17,7 @@ func BookAddOrUpdate(c echo.Context) error {
|
||||||
|
|
||||||
if bookFromString == "" {
|
if bookFromString == "" {
|
||||||
if err := c.Bind(&datBook); err != nil {
|
if err := c.Bind(&datBook); err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
|
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided."})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Decode the JSON
|
// Decode the JSON
|
||||||
|
@ -36,7 +36,7 @@ func BookAddOrUpdate(c echo.Context) error {
|
||||||
bookID, err := strconv.ParseInt(id, 10, 64)
|
bookID, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get book id"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get book id."})
|
||||||
}
|
}
|
||||||
datBook.ID = bookID
|
datBook.ID = bookID
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,11 @@ func BookAddOrUpdate(c echo.Context) error {
|
||||||
if datBook.ID != 0 {
|
if datBook.ID != 0 {
|
||||||
_, exists, err := models.GetBookByID(datBook.ID)
|
_, exists, err := models.GetBookByID(datBook.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the book exists"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the book exists."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return c.JSON(http.StatusNotFound, models.Message{"The book does not exist"})
|
return c.JSON(http.StatusNotFound, models.Message{"The book does not exist."})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func BookAddOrUpdate(c echo.Context) error {
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Added or updated a book", newBook.ID, c)
|
err = models.LogAction("Added or updated a book", newBook.ID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, newBook)
|
return c.JSON(http.StatusOK, newBook)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func BookList(c echo.Context) error {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, list)
|
return c.JSON(http.StatusOK, list)
|
||||||
|
|
|
@ -17,7 +17,7 @@ func ItemAddOrUpdate(c echo.Context) error {
|
||||||
|
|
||||||
if itemFromString == "" {
|
if itemFromString == "" {
|
||||||
if err := c.Bind(&datItem); err != nil {
|
if err := c.Bind(&datItem); err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"No item model provided"})
|
return c.JSON(http.StatusBadRequest, models.Message{"No item model provided."})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Decode the JSON
|
// Decode the JSON
|
||||||
|
@ -36,7 +36,7 @@ func ItemAddOrUpdate(c echo.Context) error {
|
||||||
itemID, err := strconv.ParseInt(id, 10, 64)
|
itemID, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item id"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item ID."})
|
||||||
}
|
}
|
||||||
datItem.ID = itemID
|
datItem.ID = itemID
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,11 @@ func ItemAddOrUpdate(c echo.Context) error {
|
||||||
if datItem.ID != 0 {
|
if datItem.ID != 0 {
|
||||||
_, exists, err := models.GetItemByID(datItem.ID)
|
_, exists, err := models.GetItemByID(datItem.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the item exists"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the item exists."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return c.JSON(http.StatusNotFound, models.Message{"The item does not exist"})
|
return c.JSON(http.StatusNotFound, models.Message{"The item does not exist."})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func ItemAddOrUpdate(c echo.Context) error {
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Added or updated an item", newItem.ID, c)
|
err = models.LogAction("Added or updated an item", newItem.ID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, newItem)
|
return c.JSON(http.StatusOK, newItem)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func ItemDelete(c echo.Context) error {
|
||||||
_, exists, err := models.GetItemByID(itemID)
|
_, exists, err := models.GetItemByID(itemID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -34,13 +34,13 @@ func ItemDelete(c echo.Context) error {
|
||||||
err = models.DeleteItemByID(itemID)
|
err = models.DeleteItemByID(itemID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete item"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete item."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Deleted an item", itemID, c)
|
err = models.LogAction("Deleted an item", itemID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, models.Message{"success"})
|
return c.JSON(http.StatusOK, models.Message{"success"})
|
||||||
|
|
|
@ -15,7 +15,7 @@ func ItemsList(c echo.Context) error {
|
||||||
list, err := models.ListItems(search)
|
list, err := models.ListItems(search)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting items"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting items."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, list)
|
return c.JSON(http.StatusOK, list)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func PublisherAddOrUpdate(c echo.Context) error {
|
||||||
if publisherFromString == "" {
|
if publisherFromString == "" {
|
||||||
// b := new(models.Publisher)
|
// b := new(models.Publisher)
|
||||||
if err := c.Bind(&datPublisher); err != nil {
|
if err := c.Bind(&datPublisher); err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"No publisher model provided"})
|
return c.JSON(http.StatusBadRequest, models.Message{"No publisher model provided."})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Decode the JSON
|
// Decode the JSON
|
||||||
|
@ -37,7 +37,7 @@ func PublisherAddOrUpdate(c echo.Context) error {
|
||||||
publisherID, err := strconv.ParseInt(id, 10, 64)
|
publisherID, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item id"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get item id."})
|
||||||
}
|
}
|
||||||
datPublisher.ID = publisherID
|
datPublisher.ID = publisherID
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ func PublisherAddOrUpdate(c echo.Context) error {
|
||||||
if datPublisher.ID != 0 {
|
if datPublisher.ID != 0 {
|
||||||
_, exists, err := models.GetPublisherByID(datPublisher.ID)
|
_, exists, err := models.GetPublisherByID(datPublisher.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the publisher exists"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the publisher exists."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return c.JSON(http.StatusNotFound, models.Message{"The publisher does not exist"})
|
return c.JSON(http.StatusNotFound, models.Message{"The publisher does not exist."})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func PublisherAddOrUpdate(c echo.Context) error {
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Added or updated a publisher", newPublisher.ID, c)
|
err = models.LogAction("Added or updated a publisher", newPublisher.ID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, newPublisher)
|
return c.JSON(http.StatusOK, newPublisher)
|
||||||
|
|
|
@ -16,14 +16,14 @@ func PublisherDelete(c echo.Context) error {
|
||||||
publisherID, err := strconv.ParseInt(id, 10, 64)
|
publisherID, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"Publisher ID is invalid"})
|
return c.JSON(http.StatusBadRequest, models.Message{"Publisher ID is invalid."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the publisher exists
|
// Check if the publisher exists
|
||||||
_, exists, err := models.GetPublisherByID(publisherID)
|
_, exists, err := models.GetPublisherByID(publisherID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get publisher"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get publisher."})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -34,13 +34,13 @@ func PublisherDelete(c echo.Context) error {
|
||||||
err = models.DeletePublisherByID(publisherID)
|
err = models.DeletePublisherByID(publisherID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete publisher"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete publisher."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the action
|
// Log the action
|
||||||
err = models.LogAction("Deleted a publisher", publisherID, c)
|
err = models.LogAction("Deleted a publisher", publisherID, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not log."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, models.Message{"success"})
|
return c.JSON(http.StatusOK, models.Message{"success"})
|
||||||
|
|
|
@ -15,7 +15,7 @@ func PublishersList(c echo.Context) error {
|
||||||
list, err := models.ListPublishers(search)
|
list, err := models.ListPublishers(search)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers."})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, list)
|
return c.JSON(http.StatusOK, list)
|
||||||
|
|
Loading…
Reference in New Issue