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

Real ball-ache trying to determine the error response.... I came up with this (sorry VB) #56

Open
trevski opened this issue Feb 24, 2018 · 1 comment

Comments

@trevski
Copy link

trevski commented Feb 24, 2018

Dim subResponse As GoCardless.Services.SubscriptionResponse
Try
subResponse = oClientApi.Subscriptions.CreateAsync(subRequest).Result
Catch ex As Exception
Dim inner As Object = ex.InnerException
Dim myTask As Task(Of String) = inner.responseMessage.content.ReadAsStringAsync()
Dim ErrorMsg As String = myTask.Result

                        Return Nothing
                    End Try

This would be very useful to add to the Docs...

@todthomson
Copy link

Hi @trevski,

I've just upgraded our app to the latest version of campaignmonitor-api aka createsend-dotnet version 6.0.0 which supports .NET Standard 2.0, for which support was added in version 5.2.0.

At some stage rather than throwing HttpRequestException they started throwing CreatesendException. The good thing about that is that it carries along with it a .Error property, containing an instance of ErrorResult, which itself provides the .Code and .Message corresponding to the error response from the Campaign Monitor API

I'm not sure when this change was made, as the exception and error result types have been there for a while, but I think they might have still been throwing generic HttpRequestExceptions (which didn't contain the code and message) for a while after that was added. Not 100% sure (I'd have to read the history).

Anyhow, the TL;DR is you can now simply catch (CreatesendException ex) or even better something like catch (CreatesendException ex) when (ex.Error.Code == "203") and then handle each exception (error response) individually as it makes sense in your app.

IMHO, the CM .NET API client is now actually useable, rather than before, when you had to guess as to the reason why you received an HttpRequestException, which made it pretty difficult to use.

Cheers,

Tod.

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