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.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;
|
||||
|
Loading…
Reference in New Issue
Block a user