Xero-NetStandard icon indicating copy to clipboard operation
Xero-NetStandard copied to clipboard

Should not throw APIException when response code is 400

Open chumingwu opened this issue 4 years ago • 10 comments

When posting an update transaction, the Resp API return response code 400 with validation error, but the NetStandard Api will throw APIException. It should not throw APIException, it should just return Response Object with validation error.

These AccountingApi methods have that issue

public Task<BankTransactions> UpdateBankTransactionAsync(string accessToken, string xeroTenantId, Guid bankTransactionID, BankTransactions bankTransactions, int? unitdp = null);

public Task<CreditNotes> UpdateCreditNoteAsync(string accessToken, string xeroTenantId, Guid creditNoteID, CreditNotes creditNotes, int? unitdp = null);

public Task<Invoices> UpdateInvoiceAsync(string accessToken, string xeroTenantId, Guid invoiceID, Invoices invoices, int? unitdp = null);

chumingwu avatar Nov 13 '20 05:11 chumingwu

Hi @chumingwu we are working to improve the validation error soon.

I would like to hear more from you on what kind of behaviour you expect.

If we still throw APIException and pass an ValidationException object, but expect developer to use try catch block to use the SDK, would this be able to better the experience?

jenksguo avatar Dec 07 '20 10:12 jenksguo

Jenks,

I would like the API do NOT throw Exception when API response 400 with validation error , just return the data with validation error.

All Create methods is in this way already.

public Task<BankTransactions> CreateBankTransactionsAsync(string accessToken, string xeroTenantId, BankTransactions bankTransactions, bool? summarizeErrors = null, int? unitdp = null);

public Task<Contacts> CreateContactsAsync(string accessToken, string xeroTenantId, Contacts contacts, bool? summarizeErrors = null);

But currently some Update Mothods (Post) will throw APIException when API server return validation error.

public Task<BankTransactions> UpdateBankTransactionAsync(string accessToken, string xeroTenantId, Guid bankTransactionID, BankTransactions bankTransactions, int? unitdp = null);

chumingwu avatar Dec 09 '20 01:12 chumingwu

Hi @chumingwu we will investigate and align the behaviour between update and create methods.

jenksguo avatar Mar 12 '21 03:03 jenksguo

Hey @chumingwu, just to let you know we will be working on the validation behaviour this sprint so hopefully we will address the issue you mentioned soon.

jenksguo avatar Apr 20 '21 01:04 jenksguo

@jenksguo @GraceYBR any updates on this?

Throwing exceptions should be for exceptional circumstances, which validation is not normally considered to be

nganbread avatar Oct 16 '21 11:10 nganbread

@nganbread jenks has moved on from Xero. @RettBehrens is heading up SDKs now, so he’s your best bet for .net.

rjaus avatar Oct 16 '21 21:10 rjaus

Hi @RettBehrens @rjaus - is this still something that is planned or being worked on? We are also finding it difficult to handle this as an ApiException instead of ApiResponse. Thanks

yosefmah avatar Feb 28 '22 15:02 yosefmah

The lack of response/action by Xero is super disappointing considering that Xero is a paid product and also considers itself to be a tech company

nganbread avatar Mar 01 '22 09:03 nganbread

Heya @yosefmah. I was contracting with Xero, but I finished up in December last year. @RettBehrens is your best bet going forward.

rjaus avatar Mar 01 '22 09:03 rjaus

Issues like this really do require attention. I am currently using my own branch of your code due to similar issues. (Item not found throwing APIException). Also, since my company paid for an account for me to even develop for you, we will not be crating pull requests against this repo.

KieranFoot avatar Jan 03 '23 11:01 KieranFoot