Skip to content

Commit

Permalink
Merge pull request #137 from avenga/log-function-errors
Browse files Browse the repository at this point in the history
log errors from evaluated functions
  • Loading branch information
Marcel Ludwig authored Mar 11, 2021
2 parents 487f992 + b562eb7 commit d3a5054
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions handler/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,31 @@ func (e *Endpoint) newResponse(req *http.Request, evalCtx *eval.Context) (*http.

statusCode := http.StatusOK
if attr, ok := content.Attributes["status"]; ok {
val, _ := attr.Expr.Value(hclCtx)
val, err := attr.Expr.Value(hclCtx)
if err != nil {
e.log.Errorf("endpoint eval error: %v", err)
}

statusCode = int(seetie.ValueToInt(val))
}
clientres.StatusCode = statusCode
clientres.Status = http.StatusText(clientres.StatusCode)

if attr, ok := content.Attributes["headers"]; ok {
val, _ := attr.Expr.Value(hclCtx)
val, err := attr.Expr.Value(hclCtx)
if err != nil {
e.log.Errorf("endpoint eval error: %v", err)
}

eval.SetHeader(val, clientres.Header)
}

if attr, ok := content.Attributes["body"]; ok {
val, _ := attr.Expr.Value(hclCtx)
val, err := attr.Expr.Value(hclCtx)
if err != nil {
e.log.Errorf("endpoint eval error: %v", err)
}

r := strings.NewReader(seetie.ValueToString(val))
clientres.Body = eval.NewReadCloser(r, nil)
}
Expand Down

0 comments on commit d3a5054

Please sign in to comment.