Files
payload/packages/db-postgres/src/utilities/parseError.ts
Alessio Gravili 7880fb402a chore: playwright support (#5262)
* working playwright

* chore: use zipped, local build of playwright instead of patching it

* chore: remove bloat

* chore: get playwright and lexical to work by fixing imports from cjs modules
2024-03-08 10:56:13 -05:00

18 lines
420 B
TypeScript

import pg from 'pg'
const { DatabaseError } = pg
/**
* Format error message with hint if available
*/
export const parseError = (err: unknown, msg: string): string => {
let formattedMsg = `${msg}`
if (err instanceof Error) {
formattedMsg += ` ${err.message}.`
if (err instanceof DatabaseError) {
msg += `: ${err.message}`
if (err.hint) msg += ` ${err.hint}.`
}
}
return formattedMsg
}