Comments (2)
Thanks, I found a way to convert ValidationError
from protovalidate-go.
in the package has this comments
// A ValidationError is returned if one or more constraints on a message are
// violated. This error type can be converted into a validate.Violations
// message via ToProto.
//
// err = validator.Validate(msg)
// var valErr *ValidationError
// if ok := errors.As(err, &valErr); ok {
// pb := valErr.ToProto()
// // ...
// }
ValidationError = errors.ValidationError
so I wrote the code based on this comments
if err := v.Validate(pr); err != nil {
var valErr *protovalidate.ValidationError
if ok := errors.As(err, &valErr); ok {
return nil, errors.New(
400,
"0",
valErr.ToProto().GetViolations()[0].GetMessage(), // I not check the err length
)
}
return nil, err
}
It's working! The API returns the error message
{
"code": 400,
"reason": "0",
"message": "xxxxxxxxxxxxxxxxxxxxxxxx",
}
Maybe we should add a check for the error length?
from protovalidate-go.
Related Issues (20)
- gen proto issue HOT 1
- [BUG] Non-deterministic error values when using `string.uuid` HOT 4
- [BUG] Some red wavy line about importing when VSCode/Goland displaying generated code HOT 3
- Vulnerability GO-2024-2609 HOT 1
- [BUG] resolveDeprecatedIndex() isn't functioning. HOT 3
- field mask validation at message level is not working HOT 1
- [BUG] Enum-related validation error messages contain numbers instead of value names HOT 1
- [Feature Request] Make dependency on PGV opt-in
- [BUG] string min_len and ignore_empty HOT 1
- [BUG] undefined: atomic.Pointer v0.3.3 HOT 1
- Part of the validation code is not generated HOT 2
- [Question] How to use protovalidate-go in github-actions HOT 2
- Document recommendation for instantiating/managing validator instances HOT 2
- [Feature Request] Allow extending default cel.Env created by protovalidate.New HOT 4
- Fails to validate a simple message HOT 2
- [BUG] error evaluating repeated.unique: internal error: runtime error: invalid memory address or nil pointer dereference HOT 1
- [BUG] Cannot build with Bzlmod HOT 13
- [Question] What's the correct way to write cel expressions for validating a single item in a repeated field? HOT 1
- [BUG] *.pb.validate.go Validate AND ValidateAll cannot use. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protovalidate-go.