A simple component to control the error message.
Install these dependencies:
yarn add @nixjs23n6/error-message
import{BaseErrorConsts,BaseErrorTypes}from'@nixjs23n6/error-message'exportconstAuthCode=20constenumify=BaseErrorConsts.enumifyError(['WRONG_OTP','TOKEN_INVALID_OR_NOT_FOUND'],0,AuthCode)exportconstourErrors=BaseErrorConsts.enumify({ ...enumify})exporttypeErrorType=keyoftypeofourErrorsexportconstAuthErrors: Record<string,BaseErrorTypes.Error<ErrorType>>={[ourErrors.WRONG_OTP]: {type: 'WRONG_OTP',code: Number(ourErrors.WRONG_OTP),stringify: (otp: string)=>`Wrong OTP ${otp}`,format: (otp: string)=>({code: AuthErrors[ourErrors.WRONG_OTPasErrorType].code,message: AuthErrors[ourErrors.WRONG_OTPasErrorType].stringify(otp),}),},[ourErrors.TOKEN_INVALID_OR_NOT_FOUND]: {type: 'TOKEN_INVALID_OR_NOT_FOUND',code: Number(ourErrors.TOKEN_INVALID_OR_NOT_FOUND),stringify: (params: {accessToken: string;refreshToken: string})=>`Token invalid or not found ${JSON.stringify(params.accessToken)}`,format: (params: {accessToken: string;refreshToken: string})=>({code: AuthErrors[ourErrors.TOKEN_INVALID_OR_NOT_FOUNDasErrorType].code,message: AuthErrors[ourErrors.TOKEN_INVALID_OR_NOT_FOUNDasErrorType].stringify(params),}),},}console.log(AuthErrors[ourErrors.WRONG_OTP].format())console.log(AuthErrors[ourErrors.TOKEN_INVALID_OR_NOT_FOUND].format())