@@ -54,36 +54,45 @@ jobs:
5454 echo "Description: $description"
5555 echo "URL: $url"
5656 echo "Method: $method"
57- echo "Data: $data"
58- echo "==========================="
5957
60- response=$(curl -s -w "\n%{http_code}" \
58+ # Store response in a temporary file to avoid string manipulation issues
59+ local temp_file=$(mktemp)
60+ local http_code=$(curl -s -w "%{http_code}" \
6161 --request "$method" "$url" \
6262 --header "Authorization: Bearer ${{ steps.bytebase-login.outputs.token }}" \
6363 --header "Content-Type: application/json" \
64- --data "$data")
65-
66- status_code=$(echo "$response" | tail -n1)
67- body=$(echo "$response" | sed '$d')
64+ --data "$data" \
65+ -o "$temp_file")
6866
69- echo "=== DEBUG: Parsed Response ==="
70- echo "Status code: $status_code"
71- echo "Body length: ${#body}"
72- echo "Body content:"
73- echo "$body"
67+ echo "=== DEBUG: Response Details ==="
68+ echo "HTTP Status: $http_code"
69+ echo "Response body:"
70+ cat "$temp_file"
7471 echo "==========================="
7572
76- if [[ $status_code -lt 200 || $status_code -ge 300 ]]; then
77- echo "Error: Failed $description. Status: $status_code"
73+ if [[ $http_code -lt 200 || $http_code -ge 300 ]]; then
74+ echo "Error: Failed $description. Status: $http_code"
75+ rm "$temp_file"
7876 return 1
7977 fi
8078
81- if [[ -z "$body" ]]; then
82- echo "Error: Empty response body"
79+ # Validate JSON response
80+ if ! python3 -c "
81+ import sys, json
82+ try :
83+ with open('$temp_file', 'r') as f :
84+ json.load(f)
85+ except json.JSONDecodeError as e :
86+ print(f'Invalid JSON : {str(e)}', file=sys.stderr)
87+ sys.exit(1)
88+ " 2>/dev/null; then
89+ echo " Error: Invalid JSON response"
90+ rm "$temp_file"
8391 return 1
8492 fi
8593
86- echo "$body"
94+ cat "$temp_file"
95+ rm "$temp_file"
8796 return 0
8897 }
8998
0 commit comments