Improved error handling when QBW file does not exist or SDK not installed. BOD-142
This commit is contained in:
@@ -45,50 +45,60 @@ namespace BodyshopPartner.Utils
|
|||||||
|
|
||||||
List<QbRequestItem> AllRequests = ParseRequest(req);
|
List<QbRequestItem> AllRequests = ParseRequest(req);
|
||||||
List<QbResponseItem> HttpResponse = new List<QbResponseItem>();
|
List<QbResponseItem> HttpResponse = new List<QbResponseItem>();
|
||||||
|
try
|
||||||
hlog("Connecting to QuickBooks. This may take a moment...");
|
|
||||||
QuickBooksInterop.ConnectToQuickBooks();
|
|
||||||
|
|
||||||
foreach (QbRequestItem request in AllRequests)
|
|
||||||
{
|
{
|
||||||
try
|
hlog("Connecting to QuickBooks. This may take a moment...");
|
||||||
|
QuickBooksInterop.ConnectToQuickBooks();
|
||||||
|
|
||||||
|
foreach (QbRequestItem request in AllRequests)
|
||||||
{
|
{
|
||||||
hlog("Processing QuickBooks request. ImEX Online Record ID:" + request.Id);
|
try
|
||||||
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequestUnManaged(request.QbXML));
|
|
||||||
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
|
|
||||||
|
|
||||||
logger.Trace(response.ToString());
|
|
||||||
logger.Debug(ResponseStatus.ToString());
|
|
||||||
hlog(ResponseStatus.ToString());
|
|
||||||
|
|
||||||
QbResponseItem r = new QbResponseItem()
|
|
||||||
{
|
{
|
||||||
Id = request.Id,
|
hlog("Processing QuickBooks request. ImEX Online Record ID:" + request.Id);
|
||||||
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
|
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequestUnManaged(request.QbXML));
|
||||||
ErrorMessage = ResponseStatus.StatusMessage
|
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
|
||||||
};
|
|
||||||
|
|
||||||
HttpResponse.Add(r);
|
logger.Trace(response.ToString());
|
||||||
}
|
logger.Debug(ResponseStatus.ToString());
|
||||||
catch (Exception Ex)
|
hlog(ResponseStatus.ToString());
|
||||||
{
|
|
||||||
//Shouldn't really get here unless something is malformed.
|
QbResponseItem r = new QbResponseItem()
|
||||||
logger.Error(Ex, "Error encountered when processing QbXML Request.\n {0}", request.QbXML);
|
{
|
||||||
QbResponseItem r = new QbResponseItem()
|
Id = request.Id,
|
||||||
|
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
|
||||||
|
ErrorMessage = ResponseStatus.StatusMessage
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponse.Add(r);
|
||||||
|
}
|
||||||
|
catch (Exception Ex)
|
||||||
{
|
{
|
||||||
Id = request.Id,
|
//Shouldn't really get here unless something is malformed.
|
||||||
Success = false,
|
logger.Error(Ex, "Error encountered when processing QbXML Request.\n {0}", request.QbXML);
|
||||||
ErrorMessage = Ex.Message
|
QbResponseItem r = new QbResponseItem()
|
||||||
};
|
{
|
||||||
|
Id = request.Id,
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = Ex.Message
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponse.Add(r);
|
||||||
|
}
|
||||||
|
|
||||||
HttpResponse.Add(r);
|
|
||||||
}
|
}
|
||||||
|
QuickBooksInterop.DisconnectFromQuickBooks();
|
||||||
|
|
||||||
|
hlog("Completed QuickBooks requests.");
|
||||||
|
|
||||||
}
|
}
|
||||||
QuickBooksInterop.DisconnectFromQuickBooks();
|
catch (Exception Ex)
|
||||||
|
{
|
||||||
hlog("Completed QuickBooks requests.");
|
logger.Error(Ex, "Error encountered while processing QuickBooks requests.");
|
||||||
|
hlog("Error encountered while processing QuickBooks requests.");
|
||||||
|
HttpResponse.Add(new QbResponseItem() { Id = "-1", Success = false, ErrorMessage = Ex.Message });
|
||||||
|
}
|
||||||
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
|
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
|
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -25,6 +26,10 @@ namespace BodyshopPartner.Utils
|
|||||||
|
|
||||||
public static void ConnectToQuickBooks()
|
public static void ConnectToQuickBooks()
|
||||||
{
|
{
|
||||||
|
if(String.IsNullOrWhiteSpace(Properties.Settings.Default.QuickBooksFilePath) || !File.Exists(Properties.Settings.Default.QuickBooksFilePath))
|
||||||
|
{
|
||||||
|
throw new Exception("The QuickBooks file specified does not exist.");
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.Debug("Attempting to connect to QuickBooks...");
|
logger.Debug("Attempting to connect to QuickBooks...");
|
||||||
@@ -58,6 +63,11 @@ namespace BodyshopPartner.Utils
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Error(ex);
|
logger.Error(ex);
|
||||||
|
if(ex.Message.Contains("80040154 Class not registered"))
|
||||||
|
{
|
||||||
|
logger.Error("QuickBooks Request Processor not registered. Is QuickBooks installed on this computer?");
|
||||||
|
throw new Exception("QuickBooks Request Processor not registered. Is QuickBooks installed on this computer?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user