Skip to content

Instantly share code, notes, and snippets.

@apie
Created March 7, 2018 16:00
Show Gist options
  • Save apie/8b80565b74ef8c7af3db8a0990ae8594 to your computer and use it in GitHub Desktop.
Save apie/8b80565b74ef8c7af3db8a0990ae8594 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Licence: MIT
# Uitvoer van commando 'http' alleen tonen bij successvolle exitcode.
# Consequentie is dat het request 2x gedaan moet worden, want opslaan in bash breekt alle kleuren etc.
# Retourneert originele exitcode.
if [ "$1" != "http" ]
then
echo "Alleen geschikt voor het commando 'http'."
exit 1
fi
if "$@" --check-status &> /dev/null; then
"$@"
else
exitcode=$?
case $exitcode in
2) echo 'Request timed out!' ;;
3) echo 'Unexpected HTTP 3xx Redirection!' ;;
4) echo 'HTTP 4xx Client Error!' ;;
5) echo 'HTTP 5xx Server Error!' ;;
6) echo 'Exceeded --max-redirects=<n> redirects!' ;;
*) echo 'Other Error!' ;;
esac
fi
exit $exitcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment