Add validator lib

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-11-03 08:19:09 +01:00
committed by Sacha Al Himdani
parent 288c59a5f2
commit f9216d30b2
102 changed files with 7409 additions and 1068 deletions

View File

@@ -24,6 +24,7 @@ import (
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/auth"
"go.probo.inc/probo/pkg/authz"
"go.probo.inc/probo/pkg/validator"
)
func RecoverFunc(ctx context.Context, err any) error {
@@ -50,6 +51,27 @@ func RecoverFunc(ctx context.Context, err any) error {
})
}
var errValidations validator.ValidationErrors
if errors.As(asError(err), &errValidations) {
gqlErrors := gqlerror.List{}
for _, err := range errValidations {
gqlErrors = append(
gqlErrors,
Invalid(
err,
map[string]any{
"cause": err.Code,
"field": err.Field,
"value": err.Value,
},
),
)
}
return gqlErrors
}
var tenantAccessErr *authz.TenantAccessError
if errTyped, ok := err.(error); ok && errors.As(errTyped, &tenantAccessErr) {
return Unauthorized()
@@ -65,5 +87,6 @@ func asError(err any) error {
if e, ok := err.(error); ok {
return e
}
return errors.New("unknown panic")
}