AFAIK in POSIX /bin/sh it's not possible to detect if a process that writes into a pipe exits with an error status.
bash has "set -o pipefail" and "$PIPESTATUS" for that.