Respond with error when searching

This commit is contained in:
Peter Stuifzand 2021-06-05 20:02:46 +02:00
parent 4c1234291a
commit ec493be52d
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -188,7 +188,10 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if channel == "" { if channel == "" {
feeds, err := h.backend.Search(query) feeds, err := h.backend.Search(query)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) respondJSON(w, map[string]interface{}{
"query": query,
"error": err.Error(),
})
return return
} }
respondJSON(w, map[string][]microsub.Feed{ respondJSON(w, map[string][]microsub.Feed{
@ -197,7 +200,10 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else { } else {
items, err := h.backend.ItemSearch(channel, query) items, err := h.backend.ItemSearch(channel, query)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) respondJSON(w, map[string]interface{}{
"query": query,
"error": err.Error(),
})
return return
} }
respondJSON(w, map[string]interface{}{ respondJSON(w, map[string]interface{}{