Fixed apigw payload processer invalid function registration

This commit is contained in:
Peter Grlica
2022-08-22 14:41:59 +02:00
parent 7d661e84be
commit 91252ac93d
2 changed files with 12 additions and 1 deletions
+3 -1
View File
@@ -203,7 +203,9 @@ func (h *processerPayload) Merge(params []byte) (types.Handler, error) {
return nil, errors.New("could not register function, body empty")
}
h.fn, _ = h.vm.RegisterFunction(h.params.Func)
if h.fn, err = h.vm.RegisterFunction(h.params.Func); err != nil {
return nil, fmt.Errorf("could not register function, invalid body: %s", err)
}
return h, err
}
+9
View File
@@ -162,6 +162,15 @@ func Test_processerPayload(t *testing.T) {
params: prepareFuncPayload(t, ``),
errv: `could not register function, body empty`,
},
{
name: "payload processer invalid body",
rq: &http.Request{
Method: "POST",
Body: ioutil.NopCloser(strings.NewReader(`[{"name":"johnny", "surname":"mnemonic"},{"name":"johnny", "surname":"knoxville"}]`)),
},
params: prepareFuncPayload(t, `.foo`),
errv: `could not register function, invalid body: could not transform payload: Unexpected "."`,
},
}
)