From 04c1ebd8281e7895869a99baa67a705e09e4fe81 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Wed, 14 Sep 2022 10:13:28 +0200 Subject: [PATCH] api: show non JSON data as error message --- dns-api.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dns-api.sh b/dns-api.sh index 7f6f210..9ff9c7a 100755 --- a/dns-api.sh +++ b/dns-api.sh @@ -17,6 +17,7 @@ # 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 2022-03-03 v1.1 <axel.hahn@iml.unibe.ch> colored output if jq is found # 2022-06-14 v1.2 <axel.hahn@iml.unibe.ch> debug comments are written to stderr +# 2022-09-14 v1.3 <axel.hahn@iml.unibe.ch> show non JSON data as error message # ====================================================================== @@ -43,7 +44,13 @@ relUrl="$1" # ----- make curl request >&2 echo "; === DNS API :: $method ${relUrl}" -curl -u $myauth -X $method "${mybaseurl}${relUrl}" 2>/dev/null \ - | ( if which jq >/dev/null 2>&1; then jq; else cat; echo ; fi ) +out=$(curl -u $myauth -X $method "${mybaseurl}${relUrl}" 2>/dev/null) +if echo "$out" | head -1 | grep '^[\[\{}]' >/dev/null ; then + echo "$out" | ( if which jq >/dev/null 2>&1; then jq; else cat; echo ; fi ) +else + echo ERROR: + echo "$out" + exit 1 +fi # ---------------------------------------------------------------------- \ No newline at end of file -- GitLab