Skip to content

chore: added exception as per rfc-9457 standards#937

Open
sbansla wants to merge 2 commits intomainfrom
api-v1-exception
Open

chore: added exception as per rfc-9457 standards#937
sbansla wants to merge 2 commits intomainfrom
api-v1-exception

Conversation

@sbansla
Copy link
Contributor

@sbansla sbansla commented Feb 4, 2026

Added exception as per rfc-9457 standards

@manisha1997
Copy link
Contributor

Quality Gate Failed Quality Gate failed

Failed conditions 69.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Can we increase the coverage?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RestStandardException class that models RFC-9457 Problem Details structure with fields for type, title, status, detail, instance, code, and validation errors
  • Included a nested ValidationError class 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
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* @return list of validation errors, or null if not present
* @return non-null list of validation errors (empty if none are present)

Copilot uses AI. Check for mistakes.
this.code = code;
this.detail = detail == null ? "" : detail;
this.instance = instance == null ? "" : instance;
this.errors = errors == null ? Collections.emptyList(): errors;
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after the colon in the ternary operator. Should be "Collections.emptyList() : errors" instead of "Collections.emptyList(): errors".

Suggested change
this.errors = errors == null ? Collections.emptyList(): errors;
this.errors = errors == null ? Collections.emptyList() : errors;

Copilot uses AI. Check for mistakes.
Comment on lines 68 to 91
* 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.
*
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* 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;
}

Copilot uses AI. Check for mistakes.
@JsonProperty("detail") final String detail,
@JsonProperty("instance") final String instance,
@JsonProperty("errors") final List<ValidationError> errors) {
super();
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
super();

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
74.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants