import { readStringProperty } from '@admin/utils/error/read-string-property' const POSTGRES_MESSAGES: Record = { '23502': 'A required value is missing.', '23503': 'This is still in use somewhere else.', '23505': 'That value is already in use.' } const AUTH_MESSAGES: Record = { INVALID_EMAIL_OR_PASSWORD: 'That email or password is incorrect.', PASSWORD_TOO_SHORT: 'That password is too short.', USER_ALREADY_EXISTS: 'That email is already in use.' } export function recognize(error: unknown): string | undefined { const authCode = readStringProperty( (error as { body?: unknown } | null)?.body ?? undefined, 'code' ) if (authCode && AUTH_MESSAGES[authCode]) return AUTH_MESSAGES[authCode] const sqlState = readStringProperty(error, 'code') if (sqlState && POSTGRES_MESSAGES[sqlState]) return POSTGRES_MESSAGES[sqlState] return undefined }