Improved error handling when QBW file does not exist or SDK not installed. BOD-142
This commit is contained in:
@@ -45,7 +45,8 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
List<QbRequestItem> AllRequests = ParseRequest(req);
|
||||
List<QbResponseItem> HttpResponse = new List<QbResponseItem>();
|
||||
|
||||
try
|
||||
{
|
||||
hlog("Connecting to QuickBooks. This may take a moment...");
|
||||
QuickBooksInterop.ConnectToQuickBooks();
|
||||
|
||||
@@ -88,7 +89,16 @@ namespace BodyshopPartner.Utils
|
||||
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