Skip to content

Commit e90a3e8

Browse files
committed
Prevent displaying message on api error
1 parent 7b244ab commit e90a3e8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

api-test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ URL=""
2121
SHOW_HEADER=0
2222
HEADER_ONLY=0
2323
SILENT=0
24+
API_ERROR=0
2425

2526
echo_v() {
2627
if [ $VERBOSE -eq 1 ]; then
@@ -71,15 +72,23 @@ run() {
7172

7273
api_factory() {
7374
for TEST_CASE in $@; do
75+
API_ERROR=0
7476
echo "${BOLD}Running Case:${RESET} $TEST_CASE"
7577
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.$TEST_CASE.description" $FILE)"
7678
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.$TEST_CASE.path" $FILE)"
7779
call_api $TEST_CASE
7880
display_results
81+
echo ""
82+
echo ""
7983
done
8084
}
8185

8286
display_results() {
87+
88+
if [[ $API_ERROR == 1 ]]; then
89+
return
90+
fi
91+
8392
local res=$(jq -r '.http_status + " " + .http_message ' <<<"$RESPONSE_HEADER")
8493
local status=$(jq -r '.http_status' <<<"$RESPONSE_HEADER")
8594
echo "Response:"
@@ -100,8 +109,6 @@ display_results() {
100109
fi
101110
echo "META:"
102111
echo "$META" | jq -C
103-
echo ""
104-
echo ""
105112
}
106113

107114
color_response() {
@@ -131,6 +138,7 @@ call_api() {
131138

132139
if [[ $raw_output == *"AUTO_API_ERROR"* ]]; then
133140
echo "Problem connecting to $URL"
141+
API_ERROR=1
134142
return 1
135143
fi
136144
local header="$(awk -v bl=1 'bl{bl=0; h=($0 ~ /HTTP\//)} /^\r?$/{bl=1} {if(h)print $0 }' <<<"$raw_output")"

0 commit comments

Comments
 (0)