You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a grpc service has a validateJS configured and an invalid message comes it, it would be nice if CC returns a grpc.status.INVALID_ARGUMENT with the validation error as message.
This is what we're doing currently to achieve the same behavior:
exportfunctionwrap<TM,TC,TR>(fieldNames: string[],f: handlerFunc<TM,TC,TR>): handlerFunc<TM,TC,TR>{returnasync(msg: TM,ctx: IDispatchContext<TC>): Promise<TR|any>=>{constnullRequiredFields=fieldNames.filter((field)=>!getField(field,msg));if(nullRequiredFields.length>0){returnnewPromise((resolve)=>resolve({code: grpc.status.INVALID_ARGUMENT,message: `Required fields are null: [${nullRequiredFields.join(", ")}]`,}));}returnawaitf(msg,ctx);};}/** * This function is to support the supply of dot-notation fields for validation * @param fieldAddress The dot delimited field address e.g. "source.location" || "a.b.c.d" * @param objectToTraverse The object on which to traverse for a reference */functiongetField(fieldAddress: string,objectToTraverse: any){returnfieldAddress.split(".").reduce(index,objectToTraverse);}functionindex(obj: any,nextAddress: string){returnobj[nextAddress];}
The text was updated successfully, but these errors were encountered:
If a grpc service has a validateJS configured and an invalid message comes it, it would be nice if CC returns a
grpc.status.INVALID_ARGUMENT
with the validation error as message.This is what we're doing currently to achieve the same behavior:
The text was updated successfully, but these errors were encountered: