mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-25 12:26:26 +00:00
validation: set errdetails.BadRequest_FieldViolation slice in errdetails.BadRequest as details
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
ec06b7c4a2
commit
5662486b3b
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
|
|
||||||
"go.linka.cloud/grpc/errors"
|
"go.linka.cloud/grpc/errors"
|
||||||
"go.linka.cloud/grpc/interceptors"
|
"go.linka.cloud/grpc/interceptors"
|
||||||
@ -52,15 +51,15 @@ func errToStatus(err error) error {
|
|||||||
}
|
}
|
||||||
switch v := err.(type) {
|
switch v := err.(type) {
|
||||||
case validatorError:
|
case validatorError:
|
||||||
return errors.InvalidArgumentd(err, validatorErrorToGrpc(v))
|
return errors.InvalidArgumentd(err, &errdetails.BadRequest{FieldViolations: []*errdetails.BadRequest_FieldViolation{validatorErrorToGrpc(v)}})
|
||||||
case validatorMultiError:
|
case validatorMultiError:
|
||||||
var details []proto.Message
|
details := &errdetails.BadRequest{}
|
||||||
for _, v := range v.AllErrors() {
|
for _, v := range v.AllErrors() {
|
||||||
if d, ok := v.(validatorError); ok {
|
if d, ok := v.(validatorError); ok {
|
||||||
details = append(details, validatorErrorToGrpc(d))
|
details.FieldViolations = append(details.FieldViolations, validatorErrorToGrpc(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.InvalidArgumentd(err, details...)
|
return errors.InvalidArgumentd(err, details)
|
||||||
default:
|
default:
|
||||||
return errors.InvalidArgument(err)
|
return errors.InvalidArgument(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user