mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Report shopify errors to the UI (Fix #3853)
This commit is contained in:
@@ -48,9 +48,15 @@ namespace BTCPayServer.Plugins.Shopify
|
|||||||
using var resp = await _httpClient.SendAsync(req);
|
using var resp = await _httpClient.SendAsync(req);
|
||||||
|
|
||||||
var strResp = await resp.Content.ReadAsStringAsync();
|
var strResp = await resp.Content.ReadAsStringAsync();
|
||||||
if (strResp?.StartsWith("{\"errors\":\"[API] Invalid API key or access token", StringComparison.OrdinalIgnoreCase) == true)
|
if (strResp.StartsWith("{", StringComparison.OrdinalIgnoreCase))
|
||||||
throw new ShopifyApiException("Invalid API key or access token");
|
{
|
||||||
|
if (JObject.Parse(strResp)["errors"]?.Value<string>() is string error)
|
||||||
|
{
|
||||||
|
if (error == "Not Found")
|
||||||
|
error = "Shop not found";
|
||||||
|
throw new ShopifyApiException(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
return strResp;
|
return strResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +79,8 @@ namespace BTCPayServer.Plugins.Shopify
|
|||||||
public async Task<string[]> CheckScopes()
|
public async Task<string[]> CheckScopes()
|
||||||
{
|
{
|
||||||
var req = CreateRequest(_credentials.ShopName, HttpMethod.Get, null, "admin/oauth/access_scopes.json");
|
var req = CreateRequest(_credentials.ShopName, HttpMethod.Get, null, "admin/oauth/access_scopes.json");
|
||||||
return JObject.Parse(await SendRequest(req))["access_scopes"].Values<JToken>()
|
var c = JObject.Parse(await SendRequest(req));
|
||||||
|
return c["access_scopes"].Values<JToken>()
|
||||||
.Select(token => token["handle"].Value<string>()).ToArray();
|
.Select(token => token["handle"].Value<string>()).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -236,16 +236,14 @@ namespace BTCPayServer.Plugins.Shopify
|
|||||||
TempData[WellKnownTempData.ErrorMessage] = "Please provide valid Shopify credentials";
|
TempData[WellKnownTempData.ErrorMessage] = "Please provide valid Shopify credentials";
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
var apiClient = new ShopifyApiClient(_clientFactory, shopify.CreateShopifyApiCredentials());
|
var apiClient = new ShopifyApiClient(_clientFactory, shopify.CreateShopifyApiCredentials());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await apiClient.OrdersCount();
|
await apiClient.OrdersCount();
|
||||||
}
|
}
|
||||||
catch (ShopifyApiException)
|
catch (ShopifyApiException err)
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.ErrorMessage] =
|
TempData[WellKnownTempData.ErrorMessage] = err.Message;
|
||||||
"Shopify rejected provided credentials, please correct values and try again";
|
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user