Instead of doing set -o pipefail and checking $? you can ...

    if [[ $? -ne 0 ]] || [[ ${PIPESTATUS[1]} -ne 0 ]]; then

... very hot. Check th ebash faq for syntax :)