Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>xero-java</artifactId>
<packaging>jar</packaging>
<name>xero-java</name>
<version>4.3.1</version>
<version>4.3.2</version>
<url>https://github.com/XeroAPI/Xero-Java</url>
<description>This is the official Java SDK for Xero API</description>
<licenses>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/xero/api/XeroApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public XeroApiException(int responseCode) {
this.responseCode = responseCode;
}

public XeroApiException(int responseCode, String message) {
super(responseCode + " response: " + message);
public XeroApiException(int responseCode, String message, Exception e) {
super(responseCode + " response: " + message, e);
this.responseCode = responseCode;
this.message = message;
}
Expand All @@ -38,14 +38,14 @@ public XeroApiException(int responseCode, Map<String, String> map) {
this.messageMap = map;
}

public XeroApiException(int responseCode, Error error) {
super(responseCode + " response: none");
public XeroApiException(int responseCode, Error error, Exception e) {
super(responseCode + " response: none", e);
this.responseCode = responseCode;
this.error = error;
}

public XeroApiException(int responseCode, String message, Error error) {
super(responseCode + " response: " + message);
public XeroApiException(int responseCode, String message, Error error, Exception e) {
super(responseCode + " response: " + message, e);
this.responseCode = responseCode;
this.message = message;
this.error = error;
Expand Down
90 changes: 45 additions & 45 deletions src/main/java/com/xero/api/XeroApiExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,76 @@ public XeroApiExceptionHandler() {

// REFACTOR ERROR HANDLER
// ACCOUNTING Validation Errors (400)
public void validationError(String objectType, com.xero.models.accounting.Error error) {
throw new XeroBadRequestException(objectType, error);
public void validationError(String objectType, com.xero.models.accounting.Error error, Exception e) {
throw new XeroBadRequestException(objectType, error, e);
}

// ASSETS Validation Errors (400)
public void validationError(String objectType, com.xero.models.assets.Error error) {
throw new XeroBadRequestException(objectType, error);
public void validationError(String objectType, com.xero.models.assets.Error error, Exception e) {
throw new XeroBadRequestException(objectType, error, e);
}

// BANKFEED Statements Validation Errors (400)
public void validationError(String objectType, Statements error) {
throw new XeroBadRequestException(objectType, error);
public void validationError(String objectType, Statements error, Exception e) {
throw new XeroBadRequestException(objectType, error, e);
}

// BANKFEED Connections Validation Errors (400)
public void validationError(String objectType, FeedConnections error) {
throw new XeroBadRequestException(objectType, error);
public void validationError(String objectType, FeedConnections error, Exception e) {
throw new XeroBadRequestException(objectType, error, e);
}

// PAYROLL UK Validation Errors
public void validationError(Integer statusCode, String objectType, com.xero.models.payrolluk.Problem error) {
public void validationError(Integer statusCode, String objectType, com.xero.models.payrolluk.Problem error, Exception e) {
if (statusCode == 400 ) {
throw new XeroBadRequestException(objectType, error);
throw new XeroBadRequestException(objectType, error, e);
} else if(statusCode == 405) {
throw new XeroMethodNotAllowedException(objectType, error);
throw new XeroMethodNotAllowedException(objectType, error, e);
}
}

// PAYROLL NZ Validation Errors
public void validationError(Integer statusCode, String objectType, com.xero.models.payrollnz.Problem error) {
public void validationError(Integer statusCode, String objectType, com.xero.models.payrollnz.Problem error, Exception e) {
if (statusCode == 400 ) {
throw new XeroBadRequestException(objectType, error);
throw new XeroBadRequestException(objectType, error, e);
} else if(statusCode == 405) {
throw new XeroMethodNotAllowedException(objectType, error);
throw new XeroMethodNotAllowedException(objectType, error, e);
} else if(statusCode == 409) {
throw new XeroConflictException(objectType, error);
throw new XeroConflictException(objectType, error, e);
}
}

// PAYROLL AU Employees Validation Errors (400)
public void validationError(String objectType, com.xero.models.payrollau.Employees employees) {
throw new XeroBadRequestException(objectType, employees);
public void validationError(String objectType, com.xero.models.payrollau.Employees employees, Exception e) {
throw new XeroBadRequestException(objectType, employees, e);
}

public void validationError(String objectType, com.xero.models.payrollau.LeaveApplications leaveApplications) {
throw new XeroBadRequestException(objectType, leaveApplications);
public void validationError(String objectType, com.xero.models.payrollau.LeaveApplications leaveApplications, Exception e) {
throw new XeroBadRequestException(objectType, leaveApplications, e);
}

public void validationError(String objectType, com.xero.models.payrollau.PayItems payItems) {
throw new XeroBadRequestException(objectType, payItems);
public void validationError(String objectType, com.xero.models.payrollau.PayItems payItems, Exception e) {
throw new XeroBadRequestException(objectType, payItems, e);
}

public void validationError(String objectType, com.xero.models.payrollau.PayRuns payRuns) {
throw new XeroBadRequestException(objectType, payRuns);
public void validationError(String objectType, com.xero.models.payrollau.PayRuns payRuns, Exception e) {
throw new XeroBadRequestException(objectType, payRuns, e);
}

public void validationError(String objectType, com.xero.models.payrollau.PayrollCalendars payrollCalendars) {
throw new XeroBadRequestException(objectType, payrollCalendars);
public void validationError(String objectType, com.xero.models.payrollau.PayrollCalendars payrollCalendars, Exception e) {
throw new XeroBadRequestException(objectType, payrollCalendars, e);
}

public void validationError(String objectType, com.xero.models.payrollau.SuperFunds superFunds) {
throw new XeroBadRequestException(objectType, superFunds);
public void validationError(String objectType, com.xero.models.payrollau.SuperFunds superFunds, Exception e) {
throw new XeroBadRequestException(objectType, superFunds, e);
}

public void validationError(String objectType, com.xero.models.payrollau.Timesheets timesheets) {
throw new XeroBadRequestException(objectType, timesheets);
public void validationError(String objectType, com.xero.models.payrollau.Timesheets timesheets, Exception e) {
throw new XeroBadRequestException(objectType, timesheets, e);
}

public void validationError(String objectType, String msg) {
throw new XeroBadRequestException(400, msg);
public void validationError(String objectType, String msg, Exception e) {
throw new XeroBadRequestException(400, msg, e);
}

// REFACTOR GENERIC ERROR HANDLER
Expand All @@ -98,34 +98,34 @@ public void execute(HttpResponseException e) {

if (statusCode == 400) {
String message = e.getMessage();
throw new XeroBadRequestException(statusCode,message);
throw new XeroBadRequestException(statusCode, message, e);

} else if (statusCode == 401) {
String message = "Unauthorized - check your scopes and confirm access to this resource";
throw new XeroUnauthorizedException(statusCode, message);
throw new XeroUnauthorizedException(statusCode, message, e);

} else if (statusCode == 403) {
String message = "Forbidden - authentication unsuccessful";
throw new XeroForbiddenException(statusCode, message);
throw new XeroForbiddenException(statusCode, message, e);

} else if (statusCode == 404) {
String message = "The resource you're looking for cannot be found";
throw new XeroNotFoundException(statusCode, message);
throw new XeroNotFoundException(statusCode, message, e);

} else if (statusCode == 429) {
String message = "You've exceeded the per " + e.getHeaders().get("x-rate-limit-problem") + " rate limit";
throw new XeroRateLimitException(statusCode, message);
throw new XeroRateLimitException(statusCode, message, e);

} else if (statusCode == 500) {
String message = "An error occurred in Xero. Check the API Status page http://status.developer.xero.com for current service status.";
throw new XeroServerErrorException(statusCode, message);
throw new XeroServerErrorException(statusCode, message, e);

} else if (statusCode > 500) {
String message = "Internal Server Error";
throw new XeroServerErrorException(statusCode, message);
throw new XeroServerErrorException(statusCode, message, e);

} else {
throw new XeroApiException(statusCode, e.getStatusMessage());
throw new XeroApiException(statusCode, e.getStatusMessage(), e);
}
}

Expand All @@ -139,27 +139,27 @@ public void execute(HttpResponseException e, ApiClient apiClient)
TypeReference<Error> errorTypeRef = new TypeReference<Error>() {
};
error = apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
throw new XeroApiException(statusCode, e.getStatusMessage(), error);
throw new XeroApiException(statusCode, e.getStatusMessage(), error, e);
} else if (statusCode == 404) {
error = new Error();
Element elementsItem = new Element();
ValidationError ve = new ValidationError();
ve.setMessage("The resource you're looking for cannot be found");
elementsItem.addValidationErrorsItem(ve);
error.addElementsItem(elementsItem);
throw new XeroApiException(statusCode, error);
throw new XeroApiException(statusCode, error, e);
} else if (statusCode == 429) {
error = new Error();
Element elementsItem = new Element();
ValidationError ve = new ValidationError();
ve.setMessage("You've exceeded the per " + e.getHeaders().get("x-rate-limit-problem") + " rate limit");
elementsItem.addValidationErrorsItem(ve);
error.addElementsItem(elementsItem);
throw new XeroApiException(statusCode, error);
throw new XeroApiException(statusCode, error, e);
} else if (statusCode == 401) {
throw new XeroApiException(401, "Unauthorized - check your scopes and confirm access to this resource" );
throw new XeroApiException(statusCode, "Unauthorized - check your scopes and confirm access to this resource", e);
} else if (statusCode != 400) {
throw new XeroApiException(statusCode, e.getStatusMessage());
throw new XeroApiException(statusCode, e.getStatusMessage(), e);
} else {
throw e;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/xero/api/XeroAuthenticationException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class XeroAuthenticationException extends XeroException {
private static final long serialVersionUID = -6292824871010327632L;

public XeroAuthenticationException(final String message) {
super(message);
public XeroAuthenticationException(final String message, final Exception e) {
super(message, e);
}
}
55 changes: 37 additions & 18 deletions src/main/java/com/xero/api/XeroBadRequestException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xero.api;

import com.xero.models.payrollau.Timesheets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -34,79 +35,91 @@ public class XeroBadRequestException extends XeroException {
private List<com.xero.models.payrollau.Timesheet> timesheetItems = new ArrayList<com.xero.models.payrollau.Timesheet>();
private List<com.xero.models.payrollau.PayRun> payRunItems = new ArrayList<com.xero.models.payrollau.PayRun>();

public XeroBadRequestException(String objectType, com.xero.models.accounting.Error error) {
public XeroBadRequestException(String objectType, com.xero.models.accounting.Error error, Exception e) {
super(e);
this.statusCode = 400;
this.type(objectType);
this.elements(error.getElements());
}

public XeroBadRequestException(String objectType, com.xero.models.assets.Error error) {
public XeroBadRequestException(String objectType, com.xero.models.assets.Error error, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.fieldValidationErrorsElements = error.getFieldValidationErrors();
}

public XeroBadRequestException(String objectType, Statements error) {
public XeroBadRequestException(String objectType, Statements error, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.statementItems = error.getItems();
}

public XeroBadRequestException(String objectType, FeedConnections error) {
public XeroBadRequestException(String objectType, FeedConnections error, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.feedConnectionItems = error.getItems();
}

public XeroBadRequestException(String objectType, com.xero.models.payrolluk.Problem problem) {
public XeroBadRequestException(String objectType, com.xero.models.payrolluk.Problem problem, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.payrollUkProblem = problem;
}

public XeroBadRequestException(String objectType, com.xero.models.payrollnz.Problem problem) {
public XeroBadRequestException(String objectType, com.xero.models.payrollnz.Problem problem, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.payrollNzProblem = problem;
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.Employees employees) {

public XeroBadRequestException(String objectType, com.xero.models.payrollau.Employees employees, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.employeeItems = employees.getEmployees();
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.LeaveApplications leaveApplications) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.LeaveApplications leaveApplications, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.leaveApplicationItems = leaveApplications.getLeaveApplications();
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayItems payItems) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayItems payItems, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
//this.payItemItems = payItems.g
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayrollCalendars payrollCalendars) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayrollCalendars payrollCalendars, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.payrollCalendarItems = payrollCalendars.getPayrollCalendars();
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.SuperFunds superFunds) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.SuperFunds superFunds, Exception e) {
this.statusCode = 400;
this.type = objectType;
this.superFundItems = superFunds.getSuperFunds();
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.Timesheets timesheets) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.Timesheets timesheets, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.timesheetItems = timesheets.getTimesheets();
}

public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayRuns payRuns) {
public XeroBadRequestException(String objectType, com.xero.models.payrollau.PayRuns payRuns, Exception e) {
super(e);
this.statusCode = 400;
this.type = objectType;
this.payRunItems = payRuns.getPayRuns();
Expand All @@ -116,7 +129,13 @@ public XeroBadRequestException(Integer statusCode, String message) {
this.statusCode = statusCode;
this.message = message;
}


public XeroBadRequestException(Integer statusCode, String message, Exception e) {
super(message, e);
this.statusCode = statusCode;
this.message = message;
}

public XeroBadRequestException statusCode(Integer statusCode) {
this.statusCode = statusCode;
return this;
Expand Down Expand Up @@ -304,7 +323,7 @@ public XeroBadRequestException payrollNzProblem(com.xero.models.payrollnz.Proble
this.payrollNzProblem = problem;
return this;
}

/**
* Exception type
* @return com.xero.models.payrollnz.Problem
Expand All @@ -313,11 +332,11 @@ public XeroBadRequestException payrollNzProblem(com.xero.models.payrollnz.Proble
public com.xero.models.payrollnz.Problem getPayrollNzProblem() {
return payrollNzProblem;
}

public void setPayrollNzProblem(com.xero.models.payrollnz.Problem problem) {
this.payrollNzProblem = problem;
}


// Payroll AU Employees
public XeroBadRequestException employeeItemsItems(List<com.xero.models.payrollau.Employee> employeeItems) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/xero/api/XeroConflictException.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public XeroConflictException(String objectType, com.xero.models.payrolluk.Proble
this.payrollUkProblem = problem;
}

public XeroConflictException(String objectType, com.xero.models.payrollnz.Problem problem) {
public XeroConflictException(String objectType, com.xero.models.payrollnz.Problem problem, Exception e) {
super(e);
this.statusCode = 409;
this.type = objectType;
this.payrollNzProblem = problem;
Expand Down
Loading