From c56d134d1d38e6ecae051cffc2145f61c58435c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Sat, 25 May 2024 23:39:04 +0200 Subject: [PATCH] Add debug logging if the product ID could not be resolved to a download URL --- .../github/action/setup_wsl/Distribution.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt b/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt index 03940f73..f2d3e70b 100644 --- a/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt +++ b/src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt @@ -19,6 +19,7 @@ package net.kautler.github.action.setup_wsl import SemVer import actions.core.debug import actions.core.info +import actions.core.isDebug import actions.exec.exec import actions.http.client.HttpClient import js.core.jso @@ -67,6 +68,35 @@ sealed class Distribution( ).await() if (response.message.statusCode != 200) { + if (isDebug()) { + val echoResponse = HttpClient().post( + requestUrl = "https://echo.free.beeceptor.com/api/GetFiles", + data = "type=ProductId&url=$productId", + additionalHeaders = recordOf( + "Content-Type" to "application/x-www-form-urlencoded" + ) + ).await() + if (echoResponse.message.statusCode == 200) { + debug("Request:\n${echoResponse.readBody().await()}") + } else { + debug("Could not get echo response (statusCode: ${echoResponse.message.statusCode} / statusMessage: ${echoResponse.message.statusMessage})") + } + + val responseMessage = JSON.stringify( + recordOf( + "httpVersion" to response.message.httpVersion, + "headers" to response.message.headers, + "trailers" to response.message.trailers, + "method" to (response.message.method ?: ""), + "url" to (response.message.url ?: ""), + "statusCode" to (response.message.statusCode ?: ""), + "statusMessage" to (response.message.statusMessage ?: ""), + "body" to response.readBody().await() + ), + space = 2 + ) + debug("Response:\n$responseMessage") + } error("Could not determine download URL (statusCode: ${response.message.statusCode} / statusMessage: ${response.message.statusMessage})") }