Add try...catch to GetProduct
This commit is contained in:
parent
e897cae23e
commit
adf66ad2a2
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Runtime.Caching;
|
using System.Runtime.Caching;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Rehau.Sku.Assist
|
namespace Rehau.Sku.Assist
|
||||||
{
|
{
|
||||||
@ -29,11 +30,13 @@ namespace Rehau.Sku.Assist
|
|||||||
return GetProduct(documentTask.Result);
|
return GetProduct(documentTask.Result);
|
||||||
}
|
}
|
||||||
public static IProduct GetProduct(IDocument document)
|
public static IProduct GetProduct(IDocument document)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
string script = document
|
string script = document
|
||||||
.Scripts
|
.Scripts
|
||||||
.Where(s => s.InnerHtml.Contains("dataLayer"))
|
.Where(s => s.InnerHtml.Contains("dataLayer"))
|
||||||
.First()
|
.FirstOrDefault()
|
||||||
.InnerHtml;
|
.InnerHtml;
|
||||||
|
|
||||||
string json = script
|
string json = script
|
||||||
@ -52,6 +55,13 @@ namespace Rehau.Sku.Assist
|
|||||||
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch (NullReferenceException e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e.Message, "Ошибка получения данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static object GetProduct(string request, ProductField field)
|
public static object GetProduct(string request, ProductField field)
|
||||||
{
|
{
|
||||||
IProduct product;
|
IProduct product;
|
||||||
|
Loading…
Reference in New Issue
Block a user