Skip to content

Commit 5272e37

Browse files
util(error): use reduce for custom errors instead of redundant classes.
1 parent e6abbeb commit 5272e37

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/util/error.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66
* LICENSE file in the root directory.
77
*/
88

9-
class RenderforestError extends Error {
10-
constructor (message) {
11-
super()
12-
this.message = message
13-
this.name = this.constructor.name
14-
}
15-
}
9+
const CUSTOM_ERRORS = [
10+
'CharacterBasedDurationError',
11+
'DurationGreaterThanMaxPossibleError',
12+
'IconAdjustableError',
13+
'MissingOrderError',
14+
'RenderforestError',
15+
'ScreenHasVideoAreaError',
16+
'ScreenIdAlreadyExistsError'
17+
]
1618

17-
class MissingOrderError extends Error {
18-
constructor (message) {
19-
super()
20-
this.message = message
21-
this.name = this.constructor.name
22-
}
23-
}
19+
const ERRORS = CUSTOM_ERRORS.reduce((acc, className) => {
20+
acc[className] = ({
21+
[className]: class extends Error {
22+
constructor (msg) {
23+
super(msg)
24+
this.name = this.constructor.name
25+
}
26+
}
27+
})[className]
2428

25-
module.exports = {
26-
RenderforestError,
27-
MissingOrderError
28-
}
29+
return acc
30+
}, {})
31+
32+
module.exports = ERRORS

0 commit comments

Comments
 (0)