Proper Error Handling
Signed-off-by: kolaente <konrad@kola-entertainments.de>
This commit is contained in:
parent
c7256eb77b
commit
d26df6c160
|
@ -16,12 +16,12 @@ func (Book) TableName() string{
|
|||
return "books"
|
||||
}
|
||||
|
||||
func ListBooks() (books []*Book) {
|
||||
func ListBooks() (books []*Book, err error) {
|
||||
|
||||
err := x.Find(&books)
|
||||
err = x.Find(&books)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting Books", err)
|
||||
}
|
||||
|
||||
return books
|
||||
return books, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package models
|
||||
|
||||
type Message struct{
|
||||
Message string
|
||||
}
|
|
@ -9,7 +9,11 @@ import (
|
|||
|
||||
func List(c echo.Context) error {
|
||||
|
||||
list := models.ListBooks()
|
||||
list, err := models.ListBooks()
|
||||
|
||||
if err != nil{
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, list)
|
||||
}
|
Loading…
Reference in New Issue