question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Custom error responses for hono/validator

See original GitHub issue

Currently, when using the validator middleware, there’s no (nice) way of providing your own error responses when the request passes validation, resulting in a plaintext response that looks something like Invalid Value: the JSON body "name" is invalid - undefined. This isn’t ideal for an API where the main format is JSON.

This feature request is to allow people to deal with formatting the error themselves.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
yusukebecommented, Sep 27, 2022

Hi! I have a few ideas on this matter. Please wait a moment, as I will introduce them later.

1reaction
yusukebecommented, Oct 13, 2022

Hi @ThatOneBro !

Exactly. I am thinking the same thing and implementing it. For example, the result objects might look like this:

    [
      {
        isValid: true,
        message: undefined,
        target: 'header',
        key: 'x-number',
        value: '12345',
        ruleName: 'asString',
        ruleType: 'type',
        jsonData: undefined
      },
      {
        isValid: false,
        message: 'Invalid Value [12345]: the request header "x-number" is invalid - isEqual',
        target: 'header',
        key: 'x-number',
        value: '12345',
        ruleName: 'isEqual',
        ruleType: 'value',
        jsonData: undefined
      }
    ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation custom error messages #1739 - Vincit/objection.js
I've tried it myself to integrate it - but failed miserably. It should tho not be so hard, based on Ajv-errors documentation: var...
Read more >
Generating custom error responses - Amazon CloudFront
Generate a custom error response when CloudFront can't deliver requested content.
Read more >
How To Implement Custom Error Responses in Express - Auth0
Learn why you may need custom error responses on 4xx errors, what a good custom format looks like, and how to apply it...
Read more >
Custom Error Responses - Apache HTTP Server Version 2.4
Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any 4xx or 5xx...
Read more >
Custom error responses (beta) · Cloudflare Rules docs
Create rules that adjust incoming requests, change Cloudflare settings, or trigger actions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found