mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-17 13:24:56 +00:00
check the error
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,19 +71,20 @@ func Handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer rsp.Body.Close()
|
defer rsp.Body.Close()
|
||||||
|
|
||||||
if rsp.StatusCode != 200 {
|
|
||||||
http.Error(w, "unexpected error", 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result := map[string]interface{}{}
|
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(rsp.Body)
|
b, err := ioutil.ReadAll(rsp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rsp.StatusCode != 200 {
|
||||||
|
log.Printf("Error calling api: status: %v %v", rsp.StatusCode, string(b))
|
||||||
|
http.Error(w, "unexpected error", 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result := map[string]interface{}{}
|
||||||
|
|
||||||
if err := json.Unmarshal(b, &result); err != nil {
|
if err := json.Unmarshal(b, &result); err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user