square / connect-csharp-sdk

C# client library for the Square Connect APIs
https://docs.connect.squareup.com/
Apache License 2.0
27 stars 25 forks source link

All calls throwing Square.Connect.Client.ApiException instead of handling and putting in response.Errors #142

Closed jslaybaugh closed 4 years ago

jslaybaugh commented 4 years ago

Using v2.22.2 from Nuget.

When we call something like

var response = paymentsApi.CreatePayment(req);
if (response.Errors != null && response.Errors.Any())
... continue from here as shown in docs

we're noticing that exceptions are being thrown and stored in our logs along the lines of

Error calling CreatePayment: {"errors": [{"code": "GENERIC_DECLINE","detail": "Authorization error: 'GENERIC_DECLINE'","category": "PAYMENT_METHOD_ERROR"}],"payment": {"id": "*****","created_at": "2019-11-08T18:21:52.699Z","updated_at": "2019-11-08T18:21:52.973Z","amount_money": {"amount": 11200,"currency": "USD"},"status": "FAILED","source_type": "CARD","card_details": {"status": "FAILED","card": {"card_brand": "AMERICAN_EXPRESS","last_4": "1001","exp_month": 11,"exp_year": 2021, .... further ommited for brevity****"}}}

So we can update our code to something like this

CreatePaymentResponse response = null;
try
{
    response = paymentsApi.CreatePayment(req);
}
catch (ApiException sqex)
{
    response = JsonConvert.DeserializeObject<CreatePaymentResponse>(sqex.ErrorContent);
}

if (response.Errors != null && response.Errors.Any())
...

But should we really need to? This is just a general decline. We're also seeing them for CVV errors. Shouldn't this be handled and exposed to us in the response.Errrors object?

ssung88 commented 4 years ago

@jslaybaugh, thank you for using our SDK. I will share your feedback with the team to further improve the SDK. In the short-term, if you want to fetch the errors in code, your code suggestion is the way to go.

StephenJosey commented 4 years ago

Closing this ticket, as this SDK is now deprecated. Please migrate and use our new .NET SDK moving forward: https://github.com/square/square-dotnet-sdk