Skip to content

Commit 53eb54f

Browse files
authored
Fix: translation of built-in Errors (fixes #23) (#24)
2 parents a4522eb + bc877f6 commit 53eb54f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/LangModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class LangModule extends AbstractModule {
149149
if (typeof lang !== 'string') {
150150
lang = this.getConfig('defaultLang')
151151
}
152-
if (key.constructor.name === 'AdaptError') {
152+
if (key.constructor.name.endsWith('Error')) {
153153
return this.translateError(lang, key)
154154
}
155155
const s = this.phrases[lang][key]
@@ -183,7 +183,7 @@ class LangModule extends AbstractModule {
183183
* @returns The translated error (if passed error is not an instance of AdaptError, the original value will be returned)
184184
*/
185185
translateError (lang, error) {
186-
return error?.constructor?.name === 'AdaptError' ? this.translate(lang, `error.${error.code}`, error.data) : error
186+
return error.constructor.name.endsWith('Error') ? this.translate(lang, `error.${error.code}`, error.data ?? error) : error
187187
}
188188
}
189189

0 commit comments

Comments
 (0)