A bare curl exits 0 on a 404 or 500, so a script carries on as if the download worked.
curl -fsS https://example.com/health || echo "check failed"
-f (--fail) makes curl exit with code 22 on an HTTP status of 400 or higher and discard the error page. -s hides the progress meter, and it hides error messages too, so -S brings them back. The combination is quiet on success and loud on failure. --fail-with-body (7.76 and newer) fails the same way but keeps the body for debugging. The manual says --fail is not fully reliable with authentication, since 401 and 407 can still pass.
Further reading: curl manual