chore: added exception as per rfc-9457 standards#937
Conversation
Can we increase the coverage? |
There was a problem hiding this comment.
Pull request overview
This PR introduces RFC-9457 compliant exception handling to the Twilio SDK by adding a new RestStandardException class for representing standardized problem details in HTTP API error responses.
Changes:
- Added
RestStandardExceptionclass that models RFC-9457 Problem Details structure with fields for type, title, status, detail, instance, code, and validation errors - Included a nested
ValidationErrorclass for representing field-level validation errors with JSON Pointer support - Added comprehensive unit tests covering both complete and minimal error response scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main/java/com/twilio/exception/RestStandardException.java | New exception class implementing RFC-9457 Problem Details specification with JSON deserialization support |
| src/test/java/com/twilio/exception/RestStandardExceptionTest.java | Unit tests verifying JSON parsing with all fields and required fields only |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Get the array of validation errors for HTTP 400/422 responses. | ||
| * | ||
| * @return list of validation errors, or null if not present |
There was a problem hiding this comment.
The documentation states that this method returns "null if not present", but the implementation always returns a non-null list (either the provided list or an empty list via Collections.emptyList()). Update the documentation to reflect that this method never returns null.
| * @return list of validation errors, or null if not present | |
| * @return non-null list of validation errors (empty if none are present) |
| this.code = code; | ||
| this.detail = detail == null ? "" : detail; | ||
| this.instance = instance == null ? "" : instance; | ||
| this.errors = errors == null ? Collections.emptyList(): errors; |
There was a problem hiding this comment.
Missing space after the colon in the ternary operator. Should be "Collections.emptyList() : errors" instead of "Collections.emptyList(): errors".
| this.errors = errors == null ? Collections.emptyList(): errors; | |
| this.errors = errors == null ? Collections.emptyList() : errors; |
| * Initialize a RFC-9457 Problem Details Exception with required fields | ||
| * | ||
| * @param type URI reference identifying the problem type | ||
| * @param title short, human-readable summary of the problem type | ||
| * @param status HTTP status code | ||
| * @param code Twilio-specific error code | ||
| */ | ||
| private RestStandardException( | ||
| @JsonProperty("code") final Integer code, | ||
| @JsonProperty("status") final Integer status, | ||
| @JsonProperty("type") final String type, | ||
| @JsonProperty("title") final String title) { | ||
| this.type = type; | ||
| this.title = title; | ||
| this.status = status; | ||
| this.code = code; | ||
| this.detail = ""; | ||
| this.instance = ""; | ||
| this.errors = Collections.emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize a RFC-9457 Problem Details Exception. | ||
| * |
There was a problem hiding this comment.
This constructor appears to be unused and unreachable. Jackson can only use one constructor marked with @JsonCreator annotation (the one on line 100), making this constructor effectively dead code. Consider removing this constructor to avoid confusion and reduce maintenance burden.
| * Initialize a RFC-9457 Problem Details Exception with required fields | |
| * | |
| * @param type URI reference identifying the problem type | |
| * @param title short, human-readable summary of the problem type | |
| * @param status HTTP status code | |
| * @param code Twilio-specific error code | |
| */ | |
| private RestStandardException( | |
| @JsonProperty("code") final Integer code, | |
| @JsonProperty("status") final Integer status, | |
| @JsonProperty("type") final String type, | |
| @JsonProperty("title") final String title) { | |
| this.type = type; | |
| this.title = title; | |
| this.status = status; | |
| this.code = code; | |
| this.detail = ""; | |
| this.instance = ""; | |
| this.errors = Collections.emptyList(); | |
| } | |
| /** | |
| * Initialize a RFC-9457 Problem Details Exception. | |
| * | |
| * Initialize a RFC-9457 Problem Details Exception. | |
| * | |
| * @param type URI reference identifying the problem type | |
| * @param title short, human-readable summary of the problem type | |
| * @param status HTTP status code | |
| * @param detail human-readable explanation specific to this occurrence | |
| * @param instance URI reference identifying the specific occurrence | |
| * @param code Twilio-specific error code | |
| * @param errors array of validation errors for HTTP 400/422 responses | |
| */ | |
| @JsonCreator | |
| private RestStandardException( | |
| @JsonProperty("code") final Integer code, | |
| @JsonProperty("status") final Integer status, | |
| @JsonProperty("type") final String type, | |
| @JsonProperty("title") final String title, | |
| @JsonProperty("detail") final String detail, | |
| @JsonProperty("instance") final String instance, | |
| @JsonProperty("errors") final List<ValidationError> errors) { | |
| super(); | |
| this.type = type; | |
| this.title = title; | |
| this.status = status; | |
| this.code = code; | |
| this.detail = detail == null ? "" : detail; | |
| this.instance = instance == null ? "" : instance; | |
| this.errors = errors == null ? Collections.emptyList(): errors; | |
| } |
| @JsonProperty("detail") final String detail, | ||
| @JsonProperty("instance") final String instance, | ||
| @JsonProperty("errors") final List<ValidationError> errors) { | ||
| super(); |
There was a problem hiding this comment.
The explicit call to super() is redundant as Java automatically inserts a no-arg super() call at the beginning of every constructor when not explicitly provided. This can be safely removed.
| super(); |
|


Added exception as per rfc-9457 standards