Skip to content
Snippets Groups Projects
Commit 04c1ebd8 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

api: show non JSON data as error message

parent b3fa78e2
Branches
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment