We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d15245f commit 37b778eCopy full SHA for 37b778e
api/api.go
@@ -2,6 +2,7 @@ package main
2
3
import (
4
"net/http"
5
+ "strings"
6
7
"errors"
8
@@ -38,7 +39,7 @@ func getBookById(id string) (*book, error) {
38
39
return &books[i], nil
40
}
41
- return nil, errors.New("book now found")
42
+ return nil, errors.New("book not found")
43
44
45
// bookById returns a book with an id
@@ -59,6 +60,12 @@ func createBook(c *gin.Context) {
59
60
var newBook book
61
62
if err := c.BindJSON(&newBook); err != nil {
63
+ c.IndentedJSON(http.StatusBadRequest, gin.H{ "error": err })
64
+ return
65
+ }
66
+
67
+ if strings.Count(newBook.ID, "") == 1 {
68
+ c.IndentedJSON(http.StatusBadRequest, gin.H{ "error": "id cannot be empty" })
69
return
70
71
0 commit comments