Throw an error from the trigger?
If the trigger function is written in PL/pgSQL, then you can raise errors with RAISE:

CREATE FUNCTION my_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
    IF random() &lt; 0.01 THEN
        RAISE EXCEPTION 'internal error';
    END IF;
    RETURN NEW;
END;
$$;