From 9b0e8f9063c1949b8137a77e4dec5ef5182e7e54 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Sat, 7 Jan 2023 01:48:26 +0100 Subject: [PATCH] Added error handling around using ACS to connect to a site URL that does not exist to give clearer feedback on this --- src/Commands/Base/PnPConnection.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Commands/Base/PnPConnection.cs b/src/Commands/Base/PnPConnection.cs index 514b01d50..4e3082b6d 100644 --- a/src/Commands/Base/PnPConnection.cs +++ b/src/Commands/Base/PnPConnection.cs @@ -196,6 +196,11 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string if (realm == null) { realm = GetRealmFromTargetUrl(url); + + if(realm == null) + { + throw new Exception($"Could not determine realm for the target site '{url}'. Please validate that a site exists at this URL."); + } } if (url.DnsSafeHost.Contains("spoppe.com")) @@ -772,7 +777,7 @@ internal static string GetRealmFromTargetUrl(Uri targetApplicationUri) client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", ""); var response = client.GetAsync(targetApplicationUri + "/_vti_bin/client.svc").GetAwaiter().GetResult(); - if (response == null) + if (response == null || response.StatusCode == System.Net.HttpStatusCode.NotFound) { return null; }