-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherrors.go
27 lines (22 loc) · 829 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main
import (
"fmt"
"log"
"net/http"
)
func readFailed(w http.ResponseWriter, err error) {
log.Println(fmt.Sprintf("error reading request body: [%s]", err.Error))
http.Error(w, "cannot read request body", http.StatusInternalServerError)
}
func bookNotFound(w http.ResponseWriter) {
log.Println("book not found in list")
http.Error(w, "book not found", http.StatusNotFound)
}
func unmarshalFailed(w http.ResponseWriter, err error) {
log.Println(fmt.Sprintf("error returned from json unmarshal: [%s]", err.Error))
http.Error(w, "cannot unmarshal json body", http.StatusInternalServerError)
}
func marshalFailed(w http.ResponseWriter, err error) {
log.Println(fmt.Sprintf("error returned from json marshal: [%s]", err.Error))
http.Error(w, "cannot marshal content to json", http.StatusInternalServerError)
}