bug: ignore errors for malformed search queries
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
// Enpoint that returns a list of articles given search terms in the post
|
// Enpoint that returns a list of articles given search terms in the post
|
||||||
// request of a search form. Uses the content template.
|
// request of a search form. Uses the content template.
|
||||||
func (app *App) UpSearch(w http.ResponseWriter, req *http.Request) {
|
func (app *App) UpSearch(w http.ResponseWriter, req *http.Request) {
|
||||||
|
// construct search query
|
||||||
searchTerms := req.FormValue("search")
|
searchTerms := req.FormValue("search")
|
||||||
if searchTerms == "" {
|
if searchTerms == "" {
|
||||||
app.Index(w, req)
|
app.Index(w, req)
|
||||||
@@ -17,7 +18,11 @@ func (app *App) UpSearch(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// get articles
|
// get articles
|
||||||
articles, err := app.articles.Search(searchTerms)
|
articles, err := app.articles.Search(searchTerms)
|
||||||
if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError); return; }
|
if err != nil {
|
||||||
|
// treat as no result
|
||||||
|
//http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// convert to viewmodel
|
// convert to viewmodel
|
||||||
articleVMs := make([]*model.ArticleViewModel, 0, len(articles))
|
articleVMs := make([]*model.ArticleViewModel, 0, len(articles))
|
||||||
|
|||||||
Reference in New Issue
Block a user