Skip to content

Commit dcc2261

Browse files
committed
chore: clean up changes
1 parent cd778a7 commit dcc2261

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

packages/corelib/src/error.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ export class UserError extends Error {
182182

183183
if (this.isSerializedUserErrorObject(err)) {
184184
return new UserError(err.rawError, err.key, err.userMessage, err.errorCode)
185+
} else if (typeof err === 'string') {
186+
const errorFromJson = this.tryFromJSON(err)
187+
if (errorFromJson) {
188+
return errorFromJson
189+
}
185190
}
186191
const err2 = err instanceof Error ? err : new Error(stringifyError(err))
187192
return new UserError(
@@ -249,4 +254,8 @@ export class UserError extends Error {
249254
toErrorString(): string {
250255
return `${translateMessage(this.userMessage, interpollateTranslation)}\n${stringifyError(this)}`
251256
}
257+
258+
toString(): string {
259+
return UserError.toJSON(this)
260+
}
252261
}

packages/shared-lib/src/lib/stringifyError.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export function stringifyError(error: unknown, noStack = false): string {
1212
str = `${(error as any).toString()}`
1313
} else {
1414
const strings: (string | undefined)[] = [
15-
stringify((error as any).rawError), // UserError
16-
stringify((error as Error).message), // Error
15+
stringify((error as any).rawError?.message), // SerializedUserError
16+
stringify((error as any).message), // UserError or Error
1717
stringify((error as any).reason), // Meteor.Error
1818
stringify((error as any).details),
1919
]
@@ -38,8 +38,12 @@ export function stringifyError(error: unknown, noStack = false): string {
3838
}
3939

4040
if (!noStack) {
41-
if (error && typeof error === 'object' && typeof (error as any).stack === 'string') {
42-
str += ', ' + (error as any).stack
41+
if (error && typeof error === 'object') {
42+
if (typeof (error as any).stack === 'string') {
43+
str += ', ' + (error as any).stack
44+
} else if (typeof (error as any).rawError?.stack === 'string') {
45+
str += ', ' + (error as any).rawError.stack
46+
}
4347
}
4448
}
4549

packages/webui/src/client/ui/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { TranslationsBundleId } from '@sofie-automation/corelib/dist/dataModel/I
1515
import { TranslationsBundles } from '../collections/index.js'
1616
import { catchError } from '../lib/lib.js'
1717
import { relativeToSiteRootUrl } from '../url.js'
18+
import { UserError } from '@sofie-automation/corelib/dist/error.js'
1819

1920
const i18nOptions = {
2021
fallbackLng: {
@@ -71,7 +72,7 @@ async function getAndCacheTranslationBundle(bundleId: TranslationsBundleId) {
7172
localStorage.setItem(`i18n.translationBundles.${bundleId}`, JSON.stringify(response.result))
7273
resolve(response.result)
7374
} else {
74-
reject(response.error)
75+
reject(UserError.fromUnknown(response.error))
7576
}
7677
},
7778
(reason) => {

0 commit comments

Comments
 (0)