11import mapValues from 'lodash/mapValues' ;
22import type { OnyxEntry } from 'react-native-onyx' ;
33import CONST from '@src/CONST' ;
4- import type { TranslationPaths } from '@src/languages/types' ;
4+ import type { TranslationPathError , TranslationPathErrors , TranslationPaths } from '@src/languages/types' ;
55import type { ErrorFields , Errors } from '@src/types/onyx/OnyxCommon' ;
66import type Response from '@src/types/onyx/Response' ;
77import type { ReceiptError } from '@src/types/onyx/Transaction' ;
@@ -45,6 +45,10 @@ function getMicroSecondOnyxErrorWithTranslationKey(error: TranslationPaths, erro
4545 return { [ errorKey ?? DateUtils . getMicroseconds ( ) ] : Localize . translateLocal ( error ) } ;
4646}
4747
48+ function getMicroSecondTranslationErrorWithTranslationKey ( error : TranslationPaths , errorKey ?: number ) : TranslationPathErrors {
49+ return { [ errorKey ?? DateUtils . getMicroseconds ( ) ] : { translationPath : error } } ;
50+ }
51+
4852/**
4953 * Creates an error object with a timestamp (in microseconds) as the key and the error message as the value.
5054 * @param error - The error message.
@@ -197,6 +201,19 @@ function isReceiptError(message: unknown): message is ReceiptError {
197201 return ( ( message as Record < string , unknown > ) ?. error ?? '' ) === CONST . IOU . RECEIPT_ERROR ;
198202}
199203
204+ function isTranslationPathError ( message : unknown ) : message is TranslationPathError {
205+ if ( typeof message === 'string' ) {
206+ return false ;
207+ }
208+ if ( Array . isArray ( message ) ) {
209+ return false ;
210+ }
211+ if ( Object . keys ( message as Record < string , unknown > ) . length === 0 ) {
212+ return false ;
213+ }
214+ return ( message as Record < string , unknown > ) ?. translationPath !== undefined ;
215+ }
216+
200217export {
201218 addErrorMessage ,
202219 getAuthenticateErrorMessage ,
@@ -212,6 +229,8 @@ export {
212229 getMicroSecondOnyxErrorWithMessage ,
213230 getMicroSecondOnyxErrorObject ,
214231 isReceiptError ,
232+ isTranslationPathError ,
233+ getMicroSecondTranslationErrorWithTranslationKey ,
215234} ;
216235
217236export type { OnyxDataWithErrors } ;
0 commit comments