File tree Expand file tree Collapse file tree
packages/recognize/src/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,25 +14,26 @@ import type { RecognizeError } from '../recognize.types.js';
1414/** @public */
1515export const createRecognizeError = (
1616 codeOrSdkError : RecognizeErrorCode | ErrorEvent ,
17- cause ?: unknown ,
17+ cause ?: Error ,
1818) : RecognizeError => {
1919 let code : RecognizeErrorCode ;
20- let errorCause : unknown ;
20+ let errorCause : Error | undefined ;
2121
2222 if ( codeOrSdkError instanceof ErrorEvent ) {
2323 const reason = ( codeOrSdkError as ErrorEvent & { reason ?: string } ) . reason ;
2424 code =
2525 ( reason && RECOGNIZE_SDK_TO_RECOGNIZE_PROXY_ERROR_MAP [ reason ] ) ||
2626 RecognizeErrorCode . SDK_ERROR ;
27- errorCause = codeOrSdkError . error ;
27+ errorCause = codeOrSdkError . error instanceof Error ? codeOrSdkError . error : undefined ;
2828 } else {
2929 code = codeOrSdkError ;
3030 errorCause = cause ;
3131 }
3232
33- const error = new Error ( code ) as RecognizeError ;
34- error . name = 'RecognizeError' ;
35- error . code = code ;
36- if ( errorCause !== undefined ) error . cause = errorCause ;
33+ const error : RecognizeError = Object . assign ( new Error ( code ) , {
34+ name : 'RecognizeError' ,
35+ code,
36+ cause : errorCause ,
37+ } ) ;
3738 return error ;
3839} ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import type { RecognizeErrorCode } from './defs/recognize-error-code.js';
2020/** @public */
2121export interface RecognizeError extends Error {
2222 code : RecognizeErrorCode ;
23- cause ?: unknown ;
23+ cause ?: Error ;
2424}
2525
2626/** @public */
You can’t perform that action at this time.
0 commit comments