CI: json-common.sh - safety check + escape

This commit is contained in:
Martin Pulec
2022-08-22 16:04:44 +02:00
parent d68df46923
commit ce6bdd79cf

View File

@@ -37,13 +37,15 @@ fetch_json() {
echo "$JSON"
}
is_int () { test "$@" -eq "$@"; }
## @brief Checks HTTP error code for success
## @param $1 returned HTTP status code
## @param $2 (optional) returned JSON (to be printed in case of error)
check_status() {
if [ $1 -lt 200 -o $1 -ge 300 ]; then
if ! is_int "$1" || [ "$1" -lt 200 ] || [ "$1" -ge 300 ]; then
echo "Wrong response status $STATUS!" >&2
if [ -n ${2-""} ]; then
if [ -n "${2-}" ]; then
echo "JSON: $(cat $2)" >&2
fi
exit 1