diff --git a/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs b/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs index 1c9cce886..6e7b8d53c 100644 --- a/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs +++ b/BTCPayServer/Plugins/Shopify/ShopifyApiClient.cs @@ -48,9 +48,15 @@ namespace BTCPayServer.Plugins.Shopify using var resp = await _httpClient.SendAsync(req); var strResp = await resp.Content.ReadAsStringAsync(); - if (strResp?.StartsWith("{\"errors\":\"[API] Invalid API key or access token", StringComparison.OrdinalIgnoreCase) == true) - throw new ShopifyApiException("Invalid API key or access token"); - + if (strResp.StartsWith("{", StringComparison.OrdinalIgnoreCase)) + { + if (JObject.Parse(strResp)["errors"]?.Value() is string error) + { + if (error == "Not Found") + error = "Shop not found"; + throw new ShopifyApiException(error); + } + } return strResp; } @@ -73,7 +79,8 @@ namespace BTCPayServer.Plugins.Shopify public async Task CheckScopes() { var req = CreateRequest(_credentials.ShopName, HttpMethod.Get, null, "admin/oauth/access_scopes.json"); - return JObject.Parse(await SendRequest(req))["access_scopes"].Values() + var c = JObject.Parse(await SendRequest(req)); + return c["access_scopes"].Values() .Select(token => token["handle"].Value()).ToArray(); } diff --git a/BTCPayServer/Plugins/Shopify/UIShopifyController.cs b/BTCPayServer/Plugins/Shopify/UIShopifyController.cs index 65bbf54c9..94f3e1aca 100644 --- a/BTCPayServer/Plugins/Shopify/UIShopifyController.cs +++ b/BTCPayServer/Plugins/Shopify/UIShopifyController.cs @@ -236,16 +236,14 @@ namespace BTCPayServer.Plugins.Shopify TempData[WellKnownTempData.ErrorMessage] = "Please provide valid Shopify credentials"; return View(vm); } - var apiClient = new ShopifyApiClient(_clientFactory, shopify.CreateShopifyApiCredentials()); try { await apiClient.OrdersCount(); } - catch (ShopifyApiException) + catch (ShopifyApiException err) { - TempData[WellKnownTempData.ErrorMessage] = - "Shopify rejected provided credentials, please correct values and try again"; + TempData[WellKnownTempData.ErrorMessage] = err.Message; return View(vm); }