Exit bash script when curl gets a non 200 HTTP status

Solution 1:

--fail, as mentioned in the man page, seems to do the job:

$ curl --fail --location http://google.com/nope
$ echo $?
22