should change ValidationError class from anonymous class to named class
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): NO
* *is this issue affecting a production system?* (yes/no): NO
#### Context
* *node version*: 19.1.0
* *module version*: 17.7.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): another framework
* *any other relevant information*:
#### What problem are you trying to solve?
When you have named classes in JS, you can use the `instanceof` operator to make comparisons. Currently, the `ValidationError` of the joi is an anonymous class, which makes it difficult to use this feature. See:
```js
const Joi = require('joi');
console.log(Joi.ValidationError)
// > [class (anonymous) extends Error]
```
#### Do you have a new or modified API suggestion to solve the problem?
It is very simple to solve this problem, it is enough that in the construction of the error the name field is defined as in the example below:
```js
class SampleError extends Error {
constructor(message) {
super(message);
this.name = 'SampleError';
}
}
console.log(SampleError)
// > [class SampleError extends Error]
```
Contributor guide
Assessment
This issue has not been assessed yet.