3
0

Remove api gw filter expression from error messages

This commit is contained in:
Tomaž Jerman
2021-09-29 19:26:06 +02:00
committed by Denis Arh
parent 7ea20c489b
commit 9929886372
4 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ func (j defaultJsonResponse) Handler() types.HandlerFunc {
rw.WriteHeader(http.StatusAccepted)
if _, err := rw.Write([]byte(`{}`)); err != nil {
return pe.Internal("could not write to body: (%v)", err)
return pe.Internal("could not write to body: %v", err)
}
return nil
+6 -6
View File
@@ -102,17 +102,17 @@ func (h header) Handler() types.HandlerFunc {
out, err := expr.NewVars(vv)
if err != nil {
return pe.Internal("could not validate headers: (%v) (%s)", err, h.params.Expr)
return pe.Internal("could not validate headers: %v", err)
}
b, err := h.eval.Test(ctx, out)
if err != nil {
return pe.InvalidData("could not validate headers: (%v) (%s)", err, h.params.Expr)
return pe.InvalidData("could not validate headers: %v", err)
}
if !b {
return pe.InvalidData("could not validate headers: (%v) (%s)", errors.New("validation failed"), h.params.Expr)
return pe.InvalidData("could not validate headers: %v", errors.New("validation failed"))
}
return nil
@@ -183,17 +183,17 @@ func (qp *queryParam) Handler() types.HandlerFunc {
out, err := expr.NewVars(vv)
if err != nil {
return pe.Internal("could not validate query parameters: (%v) (%s)", err, qp.params.Expr)
return pe.Internal("could not validate query parameters: %v", err)
}
b, err := qp.eval.Test(ctx, out)
if err != nil {
return pe.InvalidData("could not validate query parameters: (%v) (%s)", err, qp.params.Expr)
return pe.InvalidData("could not validate query parameters: %v", err)
}
if !b {
return pe.InvalidData("could not validate query parameters: (%v) (%s)", errors.New("validation failed"), qp.params.Expr)
return pe.InvalidData("could not validate query parameters: %v", errors.New("validation failed"))
}
return nil
+3 -3
View File
@@ -54,13 +54,13 @@ func Test_headerHandle(t *testing.T) {
name: "non matching value",
expr: `{"expr":"Foo == \"bar1\""}`,
headers: map[string][]string{"Foo": {"bar"}},
err: `could not validate headers: (validation failed) (Foo == "bar1")`,
err: `could not validate headers: validation failed`,
},
{
name: "non matching key",
expr: `{"expr":"Foo1 == \"bar\""}`,
headers: map[string][]string{"Foo": {"bar"}},
err: `could not validate headers: (failed to select 'Foo1' on *expr.Vars: no such key 'Foo1') (Foo1 == "bar")`,
err: `could not validate headers: failed to select 'Foo1' on *expr.Vars: no such key 'Foo1'`,
},
{
name: "regex matching key",
@@ -127,7 +127,7 @@ func Test_queryParamHandle(t *testing.T) {
name: "matching simple query parameter - missing value",
expr: `{"expr":"foo == \"bar\""}`,
url: "https://examp.le?foo=bar1",
err: `could not validate query parameters: (validation failed) (foo == "bar")`,
err: `could not validate query parameters: validation failed`,
},
{
name: "matching query parameter",
+8 -8
View File
@@ -94,7 +94,7 @@ func (h workflow) Handler() types.HandlerFunc {
payload, err := scope.Get("payload")
if err != nil {
return pe.Internal("could not get payload: (%v)", err)
return pe.Internal("could not get payload: %v", err)
}
// setup scope for workflow
@@ -107,7 +107,7 @@ func (h workflow) Handler() types.HandlerFunc {
in, err := expr.NewVars(vv)
if err != nil {
return pe.Internal("could not validate request data: (%v)", err)
return pe.Internal("could not validate request data: %v", err)
}
wp := atypes.WorkflowExecParams{
@@ -122,20 +122,20 @@ func (h workflow) Handler() types.HandlerFunc {
out, _, err := h.d.Exec(ctx, h.params.Workflow, wp)
if err != nil {
return pe.Internal("could not exec workflow: (%v)", err)
return pe.Internal("could not exec workflow: %v", err)
}
// merge out with scope
merged, err := in.Merge(out)
if err != nil {
return pe.Internal("could not receive workflow results: (%v)", err)
return pe.Internal("could not receive workflow results: %v", err)
}
mm, err := expr.CastToVars(merged)
if err != nil {
return pe.Internal("could not receive workflow results: (%v)", err)
return pe.Internal("could not receive workflow results: %v", err)
}
for k, v := range mm {
@@ -226,13 +226,13 @@ func (h processerPayload) Handler() types.HandlerFunc {
fn, err := h.vm.RegisterFunction(h.params.Func)
if err != nil {
return pe.InvalidData("could not register function: (%v)", err)
return pe.InvalidData("could not register function: %v", err)
}
out, err := fn.Exec(h.vm.New(scope))
if err != nil {
return pe.Internal("could not exec payload function: (%v)", err)
return pe.Internal("could not exec payload function: %v", err)
}
// add to scope, so next steps can get the structure
@@ -249,7 +249,7 @@ func (h processerPayload) Handler() types.HandlerFunc {
}
if err != nil {
return pe.Internal("could not write to response body: (%v)", err)
return pe.Internal("could not write to response body: %v", err)
}
return