Add try...catch to GetProduct

This commit is contained in:
Sergey Chebotar 2021-12-07 08:48:35 +03:00
parent e897cae23e
commit adf66ad2a2

View File

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