Skip to content

Commit 5ad383a

Browse files
authored
fix: error messages formatting (#476)
## Description Fix error messages formatting from ``` [Error: UndefinedErrorModuleNotLoaded] ``` to: ``` [Error: MultilingualConfiguration] ``` ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [ ] Android ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent c4600fa commit 5ad383a

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/Error.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export enum ETError {
77
LanguageNotSupported = 0x69,
88
InvalidModelSource = 0xff,
99

10-
//SpeechToText errors
10+
// SpeechToText errors
1111
MultilingualConfiguration = 0xa0,
1212
MissingDataChunk = 0xa1,
1313
StreamingNotStarted = 0xa2,
@@ -41,20 +41,16 @@ export enum ETError {
4141

4242
export const getError = (e: unknown | ETError | Error): string => {
4343
if (typeof e === 'number') {
44-
if (e in ETError) return ETError[e] as string;
45-
return ETError[ETError.UndefinedError] as string;
44+
return ETError[e] ?? ETError[ETError.UndefinedError];
4645
}
4746

4847
// try to extract number from message (can contain false positives)
4948
const error = e as Error;
5049
const errorCode = parseInt(error.message, 10);
51-
const message = Number.isNaN(errorCode)
52-
? error.message
53-
: ' ' + error.message.slice(`${errorCode}`.length).trimStart();
5450

55-
const ETErrorMessage = (
56-
errorCode in ETError ? ETError[errorCode] : ETError[ETError.UndefinedError]
57-
) as string;
51+
if (Number.isNaN(errorCode)) {
52+
return error.message;
53+
}
5854

59-
return ETErrorMessage + message;
55+
return ETError[errorCode] ?? ETError[ETError.UndefinedError];
6056
};

0 commit comments

Comments
 (0)