export const errorProtocol = { '42P04' : { name : 'PDG_ERR::DuplicateDatabase' , code : '42P04' , message : 'Database already exist.' } , '3D000' : { name : 'PDG_ERR::InvalidCatalogName' , code : '3D000' , message : 'Database does not exist.' } , '23505' : { name : 'PDG_ERR::UniqueViolation' , code : '23505' , message : 'Attempt to create multiple databases concurrently.' } , '55006' : { name : 'PDG_ERR::DropDatabaseInUse' , code : '55006' , message : 'Cannot delete a database that is being accessed by other users.' } , } ; export class PgGodError implements Error { constructor ( readonly name , readonly message , readonly code , readonly stack ? ) { } public static fromPgError ( pgError ) { return new PgGodError ( errorProtocol [ pgError . code ] ?. name || 'PDG_ERR::UnexpectedError' , ( errorProtocol [ pgError . code ] ?. message || pgError . message ) , pgError . code || 'unknown' , pgError . stack ) ; } public static dbAlreadyExist ( ) { const code = '42P04' ; return new PgGodError ( errorProtocol [ code ] . name , errorProtocol [ code ] . message , code , Error ( ) . stack ) ; } public static dbDoesNotExist ( ) { const code = '3D000' ; return new PgGodError ( errorProtocol [ code ] . name , errorProtocol [ code ] . message , code , Error ( ) . stack ) ; } }