use curl -f instead of curl | grep -v "error"

curl -f will fail if a 400 or 500 response code is returned