Here you goHere you go - This Works For Me (TM) in Ubuntu and a custom Linux build. It might be overkill for your case; lines 40-48 and 96-106 should be the most relevantother Linuxes (Linuxen?).
The reason for putting the exit code detection in $PS1 is that one host has a read-only $PROMPT_COMMAND set before .bashrc is read.