Commit 7322b1bc authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

api timeout by client handled properly using net.Timeout() in HttpError

parent 31494a7b
...@@ -3,6 +3,7 @@ package pkg ...@@ -3,6 +3,7 @@ package pkg
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"net/http" "net/http"
"strings" "strings"
"time" "time"
...@@ -69,7 +70,7 @@ func getBody(url string, m mashup) error { ...@@ -69,7 +70,7 @@ func getBody(url string, m mashup) error {
func HttpError(w http.ResponseWriter, err error) { func HttpError(w http.ResponseWriter, err error) {
// if timeout happened // if timeout happened
if strings.Contains(err.Error(), "Client.Timeout exceeded") { if err, ok:= err.(net.Error); ok && err.Timeout() {
http.Error(w, "Request to API timed out", http.StatusGatewayTimeout) http.Error(w, "Request to API timed out", http.StatusGatewayTimeout)
return // return if error is already displayed return // return if error is already displayed
} }
......
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