(ctx *InvokeContext, output *rtctrl.InvocationResponse)
| 409 | } |
| 410 | |
| 411 | func (controller *Controller) buildResponse(ctx *InvokeContext, output *rtctrl.InvocationResponse) { |
| 412 | status := http.StatusOK |
| 413 | if ctx.RunOptions.RecommendedOptions.Features.EnableMetrics { |
| 414 | defer func() { |
| 415 | ctx.Logger.V(9).Infof("user function response code %d", status) |
| 416 | ctx.Metrics.SetLabel(responseCodeLabel, strconv.Itoa(status)) |
| 417 | }() |
| 418 | } |
| 419 | |
| 420 | if ctx.Output == nil { |
| 421 | status = http.StatusBadRequest |
| 422 | ctx.Response.SetStatusCode(http.StatusBadRequest) |
| 423 | ctx.Response.SetBody([]byte(NoOutputMsg)) |
| 424 | return |
| 425 | } |
| 426 | |
| 427 | //ctx.Logger.V(6).Info("invoke output", |
| 428 | // zap.String("func_result", "(skipped)"), |
| 429 | // zap.Int("func_result_len", len(output.FuncResult)), |
| 430 | // zap.String("log_message", "(skipped)"), |
| 431 | // zap.Int("log_message_len", len(output.LogMessage)), |
| 432 | // zap.String("func_error", output.FuncError), |
| 433 | // zap.String("error_info", output.ErrorInfo)) |
| 434 | |
| 435 | funcError := output.FuncError |
| 436 | payload := getFuncResult(output) |
| 437 | var logMessage []string |
| 438 | if ctx.LogType.IsLogTypeTail() { |
| 439 | logMessage = output.LogMessage |
| 440 | } |
| 441 | |
| 442 | ctx.Response.SetStatusCode(http.StatusOK) |
| 443 | |
| 444 | if ctx.Statistic.Statistic != nil { |
| 445 | ctx.Response.SetHeader(api.HeadereasyfaasExecTime, strconv.FormatFloat(ctx.Statistic.Statistic.Duration, 'f', 3, 64)) |
| 446 | } |
| 447 | |
| 448 | if ctx.Input.EnableMetrics { |
| 449 | ctx.Metrics.rtCtrl = ctx.Statistic.Metric |
| 450 | } |
| 451 | |
| 452 | if ctx.WithStreamMode || ctx.InvokeType == api.InvokeTypeEvent { |
| 453 | return |
| 454 | } |
| 455 | if ctx.LogToBody { |
| 456 | status = buildTotallyToBody(ctx, funcError, payload, logMessage) |
| 457 | } else { |
| 458 | status = build(ctx, funcError, payload, logMessage) |
| 459 | } |
| 460 | return |
| 461 | } |
| 462 | |
| 463 | func buildTotallyToBody(ctx *InvokeContext, funcError, payload string, logMessage []string) (status int) { |
| 464 | status = http.StatusOK |
no test coverage detected