Browse Source

Let's check more things

Piotr Czajkowski 3 years ago
parent
commit
2391bfdb80
2 changed files with 8 additions and 7 deletions
  1. 2 6
      app.go
  2. 6 1
      search.go

+ 2 - 6
app.go

@@ -25,13 +25,9 @@ func (app *Application) setBaseURL(url string) {
 	app.BaseURL = url
 }
 
-func jsonDecoder(data io.ReadCloser, target interface{}) {
+func jsonDecoder(data io.ReadCloser, target interface{}) error {
 	decoder := json.NewDecoder(data)
-
-	err := decoder.Decode(target)
-	if err != nil {
-		log.Printf("Error reading json: %s", err)
-	}
+	return decoder.Decode(target)
 }
 
 func (app *Application) loadLanguages() {

+ 6 - 1
search.go

@@ -3,6 +3,7 @@ package main
 import (
 	"encoding/json"
 	"log"
+	"net/http"
 	"regexp"
 	"time"
 )
@@ -121,7 +122,11 @@ func (app *Application) search(TMs []TM, text string) SearchResults {
 		}
 
 		var tempResults ResultsFromServer
-		jsonDecoder(resp.Body, &tempResults)
+		err = jsonDecoder(resp.Body, &tempResults)
+		if err != nil {
+			log.Printf("Error decoding results: %s", err)
+			continue
+		}
 
 		if tempResults.TotalConcResult > 0 {
 			tmResults := getCleanedResults(tempResults, tm.FriendlyName)