Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assocating exceptions with tickets #3

Closed
mscappini opened this issue Sep 2, 2015 · 2 comments
Closed

Assocating exceptions with tickets #3

mscappini opened this issue Sep 2, 2015 · 2 comments

Comments

@mscappini
Copy link
Contributor

Just filing an issue for a future issue I will address in a PR.

Currently, when an exception occurs in SendRequestXML or ReceiveRequestXML, exceptions are caught and forwarded to an overridable method, but neglect to pass in the ticket if one was found or not. This makes it difficult to track errors by tickets when Web Connector comes knocking for the last error by ticket. I propose there should be a way to catch exceptions after the ticket is retrieved, then pass that ticket to the exception handling.

Solution 1

try
{
    var authenticatedTicket = authenticator.GetAuthenticationFromTicket(ticket);

    try
    {
        ...
    }
    catch (Exception ex)
    {
        OnException(authenticatedTicket, ex);
    }
}
catch (Exception ex)
{
    OnException(null, ex);
}

Soltution 2

public class QbSyncException : Exception
{
    public QbSyncException(AuthenticatedTicket ticket, Exception innerException)
        : base(null, innerException)
    {
        this.Ticket = ticket;
    }

    public AuthenticatedTicket Ticket { get; private set; }
}

try
{
    var authenticatedTicket = authenticator.GetAuthenticationFromTicket(ticket);

    try
    {
        ...
    }
    catch (Exception ex)
    {
        throw new QbSyncException(authenticatedTicket, ex);
    }
}
catch (QbSyncException ex)
{
    OnException(ex.Ticket, ex);
}
catch (Exception ex)
{
    OnException(null, ex);
}
@mscappini
Copy link
Contributor Author

I'm leaning towards solution 2. Seems cleaner to handle exception logic in the set of catches.

@jsgoupil
Copy link
Owner

jsgoupil commented Sep 2, 2015

That's a great idea. I like solution 2 as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants