Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting validation errors #650

Open
emrosenf opened this issue Aug 5, 2024 · 3 comments
Open

Formatting validation errors #650

emrosenf opened this issue Aug 5, 2024 · 3 comments

Comments

@emrosenf
Copy link

emrosenf commented Aug 5, 2024

I realize the validation errors are coming from Schema, but is there any way to further customize or improve upon this?

const LoginBody = S.Struct({
  name: S.String,
  password: S.String.pipe(S.minLength(5, { 
    message: () => 'My custom message'
  }))
})

Error message:

{
    "error": "Request validation error",
    "location": "body",
    "message": "{ readonly name: string; readonly password: a string at least 5 character(s) long }\n└─ [\"password\"]\n   └─ My custom message"
}

Preferred:

{
    "error": "Request validation error",
    "location": "body",
    "message": {
         "password": "My custom message"
    }
}
@emrosenf emrosenf changed the title Validation Error Formatter Formatting validation errors Aug 5, 2024
@emrosenf
Copy link
Author

emrosenf commented Aug 5, 2024

The logic that I want is mostly implemented In the react-hook-form/resolvers effect logic

One way to allow this is if ServerRequestParser could be a service that I could implement and then provide?

Or perhaps better: an ErrorFormatter service or function?

@emrosenf
Copy link
Author

emrosenf commented Aug 5, 2024

The Schema error message is great for a programmer, but that's not a shippable error message for a public API

@sukovanej
Copy link
Owner

I used to have a pluggable schema error formatter in the past but I got rid of it. I'll take a look and possibly reintroduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants