parent
2d4ada55a8
commit
b4af38b274
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rramiachraf/dumb/data"
|
"github.com/rramiachraf/dumb/data"
|
||||||
"github.com/rramiachraf/dumb/utils"
|
"github.com/rramiachraf/dumb/utils"
|
||||||
@ -20,19 +21,26 @@ func search(l *utils.Logger) http.HandlerFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error(err.Error())
|
l.Error(err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
utils.RenderTemplate(w, views.ErrorPage(500, "cannot reach Genius servers"), l)
|
utils.RenderTemplate(w, views.ErrorPage(500, "cannot reach Genius servers."), l)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if strings.HasPrefix(res.Header.Get("content-type"), "text/html") {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
utils.RenderTemplate(w, views.ErrorPage(500, "Cloudflare got in the way."), l)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var sRes data.SearchResponse
|
var sRes data.SearchResponse
|
||||||
|
|
||||||
d := json.NewDecoder(res.Body)
|
d := json.NewDecoder(res.Body)
|
||||||
if err = d.Decode(&sRes); err != nil {
|
if err = d.Decode(&sRes); err != nil {
|
||||||
l.Error(err.Error())
|
l.Error(err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong"), l)
|
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong."), l)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results := data.SearchResults{Query: query, Sections: sRes.Response.Sections}
|
results := data.SearchResults{Query: query, Sections: sRes.Response.Sections}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user