You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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...
The text was updated successfully, but these errors were encountered:
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
here for examples of the error responses (code and message).
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.
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
This would be very useful to add to the Docs...
The text was updated successfully, but these errors were encountered: