Skip to content

Commit 4d12441

Browse files
committed
More Readme Updates
1 parent 3494a9f commit 4d12441

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

README.md

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ The Xero Java SDK contains XeroClient which has helper methods to perform (Creat
426426
import com.xero.api.*;
427427
import com.xero.api.ApiClient;
428428
import com.xero.api.client.AccountingApi;
429-
import com.xero.models.bankfeeds.*;
429+
import com.xero.models.accounting.*;
430430

431431
// Get Xero API Resource - DEMONSTRATION ONLY get token from Cookie
432432
TokenStorage storage = new TokenStorage();
@@ -439,7 +439,6 @@ ApiClient apiClientForAccounting = new ApiClient(config.getApiUrl(),null,null,nu
439439
AccountingApi accountingApi = new AccountingApi(apiClientForAccounting);
440440
accountingApi.setOAuthToken(token, tokenSecret);
441441

442-
443442
// Get All Contacts
444443
Contacts contactList = accountingApi.getContacts(null, null, null, null, null, null);
445444
System.out.println("How many contacts did we find: " + contactList.getContacts().size());
@@ -594,62 +593,23 @@ try {
594593

595594
Below is an example of how how to handle errors.
596595

597-
```java
598-
import com.xero.api.*;
599-
import com.xero.model.*;
600-
601-
// FORCE a 404 Error - there is no contact wtih ID 1234
602-
try {
603-
Contact ContactOne = client.getContact("1234");
604-
System.out.println("Get a single Contact - ID : " + ContactOne.getContactID());
605-
} catch (XeroApiException e) {
606-
System.out.println(e.getResponseCode());
607-
System.out.println(e.getMessage());
608-
}
609-
610-
611-
// FORCE a 503 Error - try to make more than 60 API calls in a minute to trigger rate limit error.
612-
List<Contact> ContactList = client.getContacts();
613-
int num = SampleData.findRandomNum(ContactList.size());
614-
try {
615-
for(int i=65; i>1; i--){
616-
Contact ContactOne = client.getContact(ContactList.get(num).getContactID());
617-
}
618-
System.out.println("Congrats - you made over 60 calls without hitting rate limit");
619-
} catch (XeroApiException e) {
620-
System.out.println(e.getResponseCode());
621-
System.out.println(e.getMessage());
622-
}
623-
624-
```
625-
626-
Version 0.6.2 adds improved ApiException handling if you are creating multiple Invoices and pass the SummarizeError=true parameter - Thanks Lance Reid (lancedfr)
627-
628596

629597
```java
630598
import com.xero.api.*;
631-
import com.xero.model.*;
599+
import com.xero.api.ApiClient;
600+
import com.xero.api.client.AccountingApi;
601+
import com.xero.models.accounting.*;
632602

633603
try {
634-
List<Invoice> listOfInvoices = new ArrayList<Invoice>();
635-
listOfInvoices.add(SampleData.loadBadInvoice().getInvoice().get(0));
636-
listOfInvoices.add(SampleData.loadBadInvoice2().getInvoice().get(0));
637-
638-
List<Invoice> newInvoice = client.createInvoices(listOfInvoices,null,true);
639-
System.out.println("Create a new Invoice ID : " + newInvoice.get(0).getInvoiceID() + " - Reference : " +newInvoice.get(0).getReference());
604+
// BAD invoice data
640605

641606
} catch (XeroApiException e) {
642-
System.out.println(e.getResponseCode());
643-
644-
List<Elements> elements = e.getApiException().getElements();
645-
Elements element = elements.get(0);
646-
List<Object> dataContractBase = element.getDataContractBase();
647-
for (Object dataContract : dataContractBase) {
648-
Invoice failedInvoice = (Invoice) dataContract;
649-
ArrayOfValidationError validationErrors = failedInvoice.getValidationErrors();
650-
651-
System.out.println("Failure message : " + errors.get(0).getMessage());
652-
System.out.println("Failure invoice Num : " + failedInvoice.getInvoiceNumber());
607+
System.out.println("Response Code: " + e.getResponseCode());
608+
System.out.println("Error Type: " + e.getError().getType());
609+
System.out.println("Error Number: " + e.getError().getErrorNumber());
610+
System.out.println("Error Message: " + e.getError().getMessage());
611+
if (e.getResponseCode() == 400) {
612+
System.out.println("Validation Message: " + e.getError().getElements().get(0).getValidationErrors().get(0).getMessage());
653613
}
654614
}
655615

0 commit comments

Comments
 (0)