debug: log all eBay setup API responses (opt_in + policy creation) to crash_log.txt

This commit is contained in:
2026-04-17 01:48:07 +01:00
parent a780ec0089
commit d84a61b918

View File

@@ -218,6 +218,14 @@ public class EbayListingService
/// Called automatically on first 20403 error. Opts the account in to SELLING_POLICY_MANAGEMENT
/// then creates minimal default policies so posting can proceed without manual eBay setup.
/// </summary>
private static void LogSetup(string msg)
{
var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EbayListingTool");
Directory.CreateDirectory(dir);
File.AppendAllText(Path.Combine(dir, "crash_log.txt"),
$"{DateTime.Now:HH:mm:ss} [Setup] {msg}{Environment.NewLine}");
}
private async Task SetupDefaultBusinessPoliciesAsync(string token)
{
// Step 1: opt in to the Business Policies programme
@@ -227,9 +235,11 @@ public class EbayListingService
using var req = MakeRequest(HttpMethod.Post,
$"{_auth.BaseUrl}/sell/account/v1/program/opt_in", token);
req.Content = new StringContent(optInBody, Encoding.UTF8, "application/json");
await _http.SendAsync(req); // 204 = success; ignore other responses
var optInRes = await _http.SendAsync(req);
var optInBody2 = await optInRes.Content.ReadAsStringAsync();
LogSetup($"opt_in → {(int)optInRes.StatusCode} {optInBody2}");
}
catch { /* opt-in failure is non-fatal — account may already be opted in */ }
catch (Exception ex) { LogSetup($"opt_in exception: {ex.Message}"); }
// Step 2: create one policy of each required type (ignore errors — they may already exist)
await TryCreateFulfillmentPolicyAsync(token);
@@ -271,9 +281,11 @@ public class EbayListingService
$"{_auth.BaseUrl}/sell/account/v1/fulfillment_policy", token);
req.Content = new StringContent(
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
await _http.SendAsync(req);
var res2 = await _http.SendAsync(req);
var body2 = await res2.Content.ReadAsStringAsync();
LogSetup($"fulfillment_policy create → {(int)res2.StatusCode} {body2}");
}
catch { }
catch (Exception ex) { LogSetup($"fulfillment_policy exception: {ex.Message}"); }
}
private async Task TryCreatePaymentPolicyAsync(string token)
@@ -291,9 +303,11 @@ public class EbayListingService
$"{_auth.BaseUrl}/sell/account/v1/payment_policy", token);
req.Content = new StringContent(
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
await _http.SendAsync(req);
var res2 = await _http.SendAsync(req);
var body2 = await res2.Content.ReadAsStringAsync();
LogSetup($"payment_policy create → {(int)res2.StatusCode} {body2}");
}
catch { }
catch (Exception ex) { LogSetup($"payment_policy exception: {ex.Message}"); }
}
private async Task TryCreateReturnPolicyAsync(string token)
@@ -314,9 +328,11 @@ public class EbayListingService
$"{_auth.BaseUrl}/sell/account/v1/return_policy", token);
req.Content = new StringContent(
JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
await _http.SendAsync(req);
var res2 = await _http.SendAsync(req);
var body2 = await res2.Content.ReadAsStringAsync();
LogSetup($"return_policy create → {(int)res2.StatusCode} {body2}");
}
catch { }
catch (Exception ex) { LogSetup($"return_policy exception: {ex.Message}"); }
}
private async Task CreateMerchantLocationAsync(string token, string postcode)
@@ -533,3 +549,5 @@ public class EbayListingService