mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-12-22 00:40:46 +00:00
errors: add BadRequestDetails
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
e70369a902
commit
19787f85ca
20
errors/details.go
Normal file
20
errors/details.go
Normal file
@ -0,0 +1,20 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
)
|
||||
|
||||
// BadRequestDetails returns an error details for an invalid argument.
|
||||
// fd is a list of field / description pairs.
|
||||
func BadRequestDetails(fd ...string) *errdetails.BadRequest {
|
||||
var fieldViolations []*errdetails.BadRequest_FieldViolation
|
||||
for i := 0; i < len(fd); i += 2 {
|
||||
fieldViolations = append(fieldViolations, &errdetails.BadRequest_FieldViolation{
|
||||
Field: fd[i],
|
||||
Description: fd[i+1],
|
||||
})
|
||||
}
|
||||
return &errdetails.BadRequest{
|
||||
FieldViolations: fieldViolations,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user