To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this:
command 2>&1 | tee -a file.txt
Perhaps you could put the exit value from PIPESTATUS into $?
$?
command 2>&1 | tee -a file.txt ; ( exit ${PIPESTATUS} )