Commit f785ee22 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

timeout using client on diag fix

parent 0b9066f3
...@@ -15,12 +15,12 @@ func Dhandler(w http.ResponseWriter, r *http.Request) { ...@@ -15,12 +15,12 @@ func Dhandler(w http.ResponseWriter, r *http.Request) {
err := pkg.GetDiag(&diagnostics) err := pkg.GetDiag(&diagnostics)
// if error was encountered: print error, else: return diagnostics // if error was encountered: print error, else: return diagnostics
if err != nil { if err == nil {
http.Error(w, err.Error(), http.StatusBadGateway)
} else {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(&diagnostics); err != nil { if err := json.NewEncoder(w).Encode(&diagnostics); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} else {
http.Error(w, err.Error(), http.StatusBadGateway)
} }
} }
...@@ -2,7 +2,6 @@ package pkg ...@@ -2,7 +2,6 @@ package pkg
import ( import (
"fmt" "fmt"
"net/http"
"time" "time"
) )
...@@ -43,9 +42,9 @@ func GetDiag(d* Diag) error { ...@@ -43,9 +42,9 @@ func GetDiag(d* Diag) error {
return nil return nil
} }
// Gets GBIF-api status code // Gets GBIF-api status code (uses http.client defined in funcs.go)
func getGbifStatus(d *Diag) error { func getGbifStatus(d *Diag) error {
resp, err := http.Get(gbifApi) resp, err := client.Get(gbifApi)
if err != nil { if err != nil {
return err return err
} }
...@@ -53,9 +52,9 @@ func getGbifStatus(d *Diag) error { ...@@ -53,9 +52,9 @@ func getGbifStatus(d *Diag) error {
return nil return nil
} }
// Gets country-api status code // Gets country-api status code (uses http.client defined in funcs.go)
func getRestStatus(d *Diag) error { func getRestStatus(d *Diag) error {
resp, err := http.Get(restApi) resp, err := client.Get(restApi)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
// creates http client for ensuring timely timeouts // creates http client for ensuring timely timeouts
var client = http.Client{ var client = http.Client{
Timeout: 5 * time.Second, Timeout: 15 * time.Second,
} }
// allowing access to "overloaded" functions // allowing access to "overloaded" functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment