mirror of
https://github.com/openfaas/faas.git
synced 2025-06-13 10:46:46 +00:00
Improve errors when backend doesn't return JSON
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
887c804254
commit
bc2eeff467
@ -144,7 +144,7 @@ func (e *Exporter) getHTTPClient(timeout time.Duration) http.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.FunctionStatus, error) {
|
func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.FunctionStatus, error) {
|
||||||
timeout := 3 * time.Second
|
timeout := 5 * time.Second
|
||||||
proxyClient := e.getHTTPClient(timeout)
|
proxyClient := e.getHTTPClient(timeout)
|
||||||
|
|
||||||
endpointURL.Path = path.Join(endpointURL.Path, "/system/functions")
|
endpointURL.Path = path.Join(endpointURL.Path, "/system/functions")
|
||||||
@ -170,10 +170,11 @@ func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.
|
|||||||
return services, readErr
|
return services, readErr
|
||||||
}
|
}
|
||||||
|
|
||||||
unmarshalErr := json.Unmarshal(bytesOut, &services)
|
if err := json.Unmarshal(bytesOut, &services); err != nil {
|
||||||
if unmarshalErr != nil {
|
return services, fmt.Errorf("error unmarshalling response: %s, error: %s",
|
||||||
return services, unmarshalErr
|
string(bytesOut), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return services, nil
|
return services, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
|
|||||||
get.SetBasicAuth(e.credentials.User, e.credentials.Password)
|
get.SetBasicAuth(e.credentials.User, e.credentials.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := 3 * time.Second
|
timeout := 5 * time.Second
|
||||||
proxyClient := e.getHTTPClient(timeout)
|
proxyClient := e.getHTTPClient(timeout)
|
||||||
|
|
||||||
res, err := proxyClient.Do(get)
|
res, err := proxyClient.Do(get)
|
||||||
@ -203,9 +204,8 @@ func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
|
|||||||
return namespaces, readErr
|
return namespaces, readErr
|
||||||
}
|
}
|
||||||
|
|
||||||
unmarshalErr := json.Unmarshal(bytesOut, &namespaces)
|
if err := json.Unmarshal(bytesOut, &namespaces); err != nil {
|
||||||
if unmarshalErr != nil {
|
return namespaces, fmt.Errorf("error unmarshalling response: %s, error: %s", string(bytesOut), err)
|
||||||
return namespaces, unmarshalErr
|
|
||||||
}
|
}
|
||||||
return namespaces, nil
|
return namespaces, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user