From 90698425a2ac3059b9ae837640f49cd3c6c6152d Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Tue, 18 Mar 2025 13:25:06 +0100 Subject: [PATCH] Api update --- misc/api.func | 15 +++++++++++---- misc/build.func | 12 ++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/misc/api.func b/misc/api.func index 92e7bc3..44b17ab 100644 --- a/misc/api.func +++ b/misc/api.func @@ -43,11 +43,12 @@ EOF -H "Content-Type: application/json" \ -d "$JSON_PAYLOAD") || true } -echo -e "Posting to API... " + get_error_description() { local exit_code="$1" case "$exit_code" in + 0) echo " " ;; 1) echo "General error: An unspecified error occurred." ;; 2) echo "Incorrect shell usage or invalid command arguments." ;; 3) echo "Unexecuted function or invalid shell condition." ;; @@ -155,10 +156,16 @@ post_update_to_api() { fi local status="${1:-failed}" - local exit_code="${2:-0}" - local error_description="$(get_error_description "$exit_code")" + if [[ "$status" == "failed" ]]; then + local exit_code="${2:-1}" + elif [[ "$status" == "success" ]]; then + local exit_code="${2:-0}" + fi + + local API_URL="http://api.community-scripts.org/dev/upload/updatestatus" - local error="${exit_code}: ${error_description}" + error=$(get_error_description "$exit_code") + if [ -z "$error" ]; then error="Unknown error" diff --git a/misc/build.func b/misc/build.func index 85071c2..52a5221 100644 --- a/misc/build.func +++ b/misc/build.func @@ -1591,14 +1591,10 @@ silent() { exit_script() { exit_code=$? # Capture exit status - - if [ $exit_code -ne 0 ]; then - local error_description="$(get_error_description "$exit_code")" - post_update_to_api "failed" "$exit_code" "$error_description" - fi + post_update_to_api "failed" "$exit_code" } trap 'exit_script' EXIT -trap 'post_update_to_api "failed" "$BASH_COMMAND"' ERR -trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT -trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM +trap 'post_update_to_api "failed" "2"' ERR +trap 'post_update_to_api "failed" "130"' SIGINT +trap 'post_update_to_api "failed" "143"' SIGTERM