diff --git a/server/templates/go_template.go b/server/templates/go_template.go index 4fa2741..56d1011 100644 --- a/server/templates/go_template.go +++ b/server/templates/go_template.go @@ -64,14 +64,15 @@ func (*goTemplateJsonEngine) Execute(request types.Request, script string) (*typ return nil, fmt.Errorf("failed to unmarshal response from dynamic template: %w", err) } - body := tmplResult["body"] - if _, ok := body.(string); !ok { - b, err := json.Marshal(body) - if err != nil { - log.WithError(err).Error("Failed to marshal response body as JSON") - return nil, fmt.Errorf("failed to marshal response body as JSON: %w", err) + if body := tmplResult["body"]; body != nil { + if _, ok := body.(string); !ok { + b, err := json.Marshal(body) + if err != nil { + log.WithError(err).Error("Failed to marshal response body as JSON") + return nil, fmt.Errorf("failed to marshal response body as JSON: %w", err) + } + tmplResult["body"] = string(b) } - tmplResult["body"] = string(b) } b, err := json.Marshal(tmplResult)