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<QbResponseItem> HttpResponse = new List<QbResponseItem>();
|
||||
|
||||
hlog("Connecting to QuickBooks. This may take a moment...");
|
||||
QuickBooksInterop.ConnectToQuickBooks();
|
||||
|
||||
foreach (QbRequestItem request in AllRequests)
|
||||
try
|
||||
{
|
||||
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);
|
||||
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()
|
||||
try
|
||||
{
|
||||
Id = request.Id,
|
||||
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
|
||||
ErrorMessage = ResponseStatus.StatusMessage
|
||||
};
|
||||
hlog("Processing QuickBooks request. ImEX Online Record ID:" + request.Id);
|
||||
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequestUnManaged(request.QbXML));
|
||||
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
|
||||
|
||||
HttpResponse.Add(r);
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
//Shouldn't really get here unless something is malformed.
|
||||
logger.Error(Ex, "Error encountered when processing QbXML Request.\n {0}", request.QbXML);
|
||||
QbResponseItem r = new QbResponseItem()
|
||||
logger.Trace(response.ToString());
|
||||
logger.Debug(ResponseStatus.ToString());
|
||||
hlog(ResponseStatus.ToString());
|
||||
|
||||
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,
|
||||
Success = false,
|
||||
ErrorMessage = Ex.Message
|
||||
};
|
||||
//Shouldn't really get here unless something is malformed.
|
||||
logger.Error(Ex, "Error encountered when processing QbXML Request.\n {0}", request.QbXML);
|
||||
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();
|
||||
|
||||
hlog("Completed QuickBooks requests.");
|
||||
catch (Exception Ex)
|
||||
{
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -25,6 +26,10 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
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
|
||||
{
|
||||
logger.Debug("Attempting to connect to QuickBooks...");
|
||||
@@ -58,6 +63,11 @@ namespace BodyshopPartner.Utils
|
||||
catch (Exception 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