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.

Custom errors to send custom status codes

See original GitHub issue

I am trying to implement a validation chain, where some errors should return 400 (with a specific message) but some other should return 403 (with a specific message). I have found no neat way to do this, as I handle all validationResult(req) at the end of the validation chain. It would be cool to be able set like withStatus that gets attached to the results, or maybe even withCustom to add custom things to it. Or maybe there is an easier, more intuitive way?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thernstigcommented, Apr 8, 2021

Will try it when I get a chance, thanks.

1reaction
fedecicommented, Apr 8, 2021
.withMessage((value, { req }) => {
  return { ... }
})

Does this work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can we create custom HTTP Status codes? - Stack Overflow
Yes, as long as you respect the class -- that is, 2xx for success, 4xx for Client error, etc. So you can return...
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 (beta) · Cloudflare Rules docs
During the beta, you can define custom error responses using inline templates and specify the response's content type and HTTP status code.
Read more >
A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >
How to set Custom Error Message and Status code for an ...
This article goes over the process to define custom error messages and status codes in an HTTP service, details how to handle them...
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