New API tested
This commit is contained in:
16
view/json.go
16
view/json.go
@@ -27,15 +27,7 @@ func jsonHandler(g storage.Graph) http.Handler {
|
||||
}{
|
||||
{
|
||||
path: "/who/",
|
||||
foo: httpwho,
|
||||
},
|
||||
{
|
||||
path: "/meet/",
|
||||
foo: httpmeet,
|
||||
},
|
||||
{
|
||||
path: "/isnow/",
|
||||
foo: httpisnow,
|
||||
foo: who,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,8 +37,12 @@ func jsonHandler(g storage.Graph) http.Handler {
|
||||
foo := route.foo
|
||||
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := foo(g, w, r); err != nil {
|
||||
status := http.StatusInternalServerError
|
||||
if strings.Contains(err.Error(), "collision") {
|
||||
status = http.StatusConflict
|
||||
}
|
||||
b, _ := json.Marshal(map[string]string{"error": err.Error()})
|
||||
http.Error(w, string(b), http.StatusInternalServerError)
|
||||
http.Error(w, string(b), status)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc(nopath, http.NotFound)
|
||||
|
||||
Reference in New Issue
Block a user