mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Addressing comments
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const FN_CALL_ID = "Fn_call_id"
|
||||
|
||||
func EnvAsHeader(req *http.Request, selectedEnv []string) {
|
||||
detectedEnv := os.Environ()
|
||||
if len(selectedEnv) > 0 {
|
||||
@@ -55,17 +57,27 @@ func CallFN(u string, content io.Reader, output io.Writer, method string, env []
|
||||
if err != nil {
|
||||
return fmt.Errorf("error running route: %s", err)
|
||||
}
|
||||
if call_id, found := resp.Header["Fn_call_id"]; found {
|
||||
// for sync calls
|
||||
if call_id, found := resp.Header[FN_CALL_ID]; found {
|
||||
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", call_id[0]))
|
||||
io.Copy(output, resp.Body)
|
||||
} else {
|
||||
// for async calls and error discovering
|
||||
c := &callID{}
|
||||
json.NewDecoder(resp.Body).Decode(c)
|
||||
err = json.NewDecoder(resp.Body).Decode(c)
|
||||
if err == nil {
|
||||
// decode would not fail in both cases:
|
||||
// - call id in body
|
||||
// - error in body
|
||||
// that's why we need to check values of attributes
|
||||
if c.CallID != "" {
|
||||
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", c.CallID))
|
||||
} else {
|
||||
fmt.Fprint(output, fmt.Sprintf("Error: %v\n", c.Error.Message))
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
|
||||
Reference in New Issue
Block a user