hapijs / hapijs/joi

should change ValidationError class from anonymous class to named class

Open
#2,897 1 comment 2 reactions 0 assignees View on GitHub
feature
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.