import { ConflictError , ServerError } from '@mds-core/mds-utils' ; const isError = ( error ) : error is Error => error instanceof Error ; const hasProperty = < T extends string > ( property , error ) : error is { [ P in T ] : string ; } => isError ( error ) && property in error ; const getProperty = < T extends string > ( property , error ) : string | undefined => hasProperty ( property , error ) ? error [ property ] : undefined ; export const RepositoryError = ( error ) => { if ( isError ( error ) ) { const code = getProperty ( 'code' , error ) ; if ( code === '23505' ) { return new ConflictError ( getProperty ( 'detail' , error ) , error ) ; } return error ; } return new ServerError ( 'Unexpected Server Error' , error ) ; } ;