Skip to content

Commit f3f9d17

Browse files
authored
Merge pull request #345 from EasyPost/error_alternative_format
feat: deserialize alternative format errors
2 parents 4509c3a + 61d88e0 commit f3f9d17

31 files changed

+375
-213
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
## Next Release
44

55
- Adds `WebhookCustomHeader` model, allowing `custom_headers` to be passed when creating/updating a webhook
6+
- Fixes error parsing
7+
- Allows for alternative format of `errors` field (previously we deserialized the `errors` field into a list of `Error` objects; however, sometimes the errors are simply a list of strings. This change make the `errors` field a list of `Object` allowing for either the new `FieldError` object or a list of strings. Users will need to check for the type of error returned and handle appropriately)
8+
- Removed the unused `Error` model
9+
- Added an explicit `AddressVerificationFieldError` model
10+
- The `BetaPaymentRefund` now uses a list of `FieldError` instead of `Error` for the `errors` field
611
- Corrects payload wrapping for updating a webhook
712
- Bumps dependencies
813

src/main/java/com/easypost/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.easypost;
22

3+
import com.easypost.exception.APIException;
34
import com.easypost.http.HashMapSerializer;
45
import com.easypost.model.AddressVerification;
56
import com.easypost.model.AddressVerificationDeserializer;
6-
import com.easypost.model.Error;
77
import com.easypost.model.ErrorDeserializer;
88
import com.easypost.model.SmartrateCollection;
99
import com.easypost.model.SmartrateCollectionDeserializer;
@@ -80,7 +80,7 @@ public abstract static class Http {
8080
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
8181
.registerTypeAdapter(HashMap.class, new HashMapSerializer())
8282
.registerTypeAdapter(SmartrateCollection.class, new SmartrateCollectionDeserializer())
83-
.registerTypeAdapter(Error.class, new ErrorDeserializer())
83+
.registerTypeAdapter(APIException.class, new ErrorDeserializer())
8484
.registerTypeAdapter(AddressVerification.class, new AddressVerificationDeserializer())
8585
.registerTypeAdapter(StatelessRate[].class, new StatelessRateDeserializer())
8686
.registerTypeAdapter(Webhook[].class, new WebhookDeserializer()).create();
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class BadRequestError extends APIException {
98
/**
109
* BadRequestError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public BadRequestError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public BadRequestError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class ForbiddenError extends APIException {
98
/**
109
* ForbiddenError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public ForbiddenError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public ForbiddenError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class GatewayTimeoutError extends APIException {
98
/**
109
* GatewayTimeoutError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public GatewayTimeoutError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public GatewayTimeoutError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class InternalServerError extends APIException {
98
/**
109
* InternalServerError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public InternalServerError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public InternalServerError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class InvalidRequestError extends APIException {
98
/**
109
* InvalidRequestError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public InvalidRequestError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public InvalidRequestError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class MethodNotAllowedError extends APIException {
98
/**
109
* MethodNotAllowedError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public MethodNotAllowedError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public MethodNotAllowedError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class NotFoundError extends APIException {
98
/**
109
* NotFoundError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public NotFoundError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public NotFoundError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.easypost.exception.API;
22

3-
import java.util.List;
4-
5-
import com.easypost.model.Error;
63
import com.easypost.exception.APIException;
74

5+
import java.util.List;
6+
87
public class PaymentError extends APIException {
98
/**
109
* PaymentError constructor.
1110
*
1211
* @param message the exception message
1312
* @param code the exception code
14-
* @param statusCode the exception status code
1513
* @param errors the errors array
14+
* @param statusCode the exception status code
1615
*/
17-
public PaymentError(final String message, final String code, final int statusCode, List<Error> errors) {
18-
super(message, code, statusCode, errors);
16+
public PaymentError(final String message, final String code, List<Object> errors, final int statusCode) {
17+
super(message, code, errors, statusCode);
1918
}
2019
}

0 commit comments

Comments
 (0)