Skip to content

fix: expose unsupported content types as client exceptions - #2189

Merged
Vincent Biret (baywet) merged 3 commits into
microsoft:mainfrom
Shubham-Padkonde:fix/unsupported-content-client-exception
Sep 21, 2026
Merged

Vincent Biret (baywet) merged 3 commits into
microsoft:mainfrom
Shubham-Padkonde:fix/unsupported-content-client-exception

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

Fixes #1683, following the proposed ClientException approach in the issue discussion.

An unregistered response content type, such as text/html returned during an outage, currently throws a plain RuntimeException from ParseNodeFactoryRegistry. Applications cannot distinguish this client-side processing failure without catching unrelated runtime errors. The serialization-writer registry has the same problem for unsupported request formats.

Add ClientException as an unchecked exception with the standard message/cause constructors, and use it for missing-factory failures in both registries. The existing messages and argument-validation exception types are preserved. This provides a specific catch target separate from ApiException, which represents service error responses; it does not replace runtime exceptions throughout the rest of the library.

Regression coverage exercises unsupported response content types, both writer backing-store option values, unchanged invalid-argument behavior, and successful vendor-specific JSON resolution. With the original registry behavior, three cases fail and two controls pass. A narrowly scoped SpotBugs exclusion covers only deliberate null-argument calls in the validation test.

Validation: JDK 21, Gradle 9.7.1 (matching the wrapper), full build -Pjava8=true with the Java 8 compatibility toolchain, including Spotless and SpotBugs. No live Microsoft Graph requests or Android build were run.

AI assistance: Codex assisted with implementation and validation. No separate human review is claimed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Adds a dedicated unchecked ClientException for unsupported serialization and parsing content types.

Changes:

  • Introduces ClientException with standard constructors.
  • Updates both factory registries to throw it while preserving messages and validation behavior.
  • Adds regression tests and a narrowly scoped SpotBugs exclusion.
File Description
components/​abstractions/​src/​test/​java/​com/​microsoft/​kiota/​serialization/​FactoryRegistryExceptionTest.java Updated as part of this pull request.
components/​abstractions/​src/​main/​java/​com/​microsoft/​kiota/​serialization/​SerializationWriterFactoryRegistry.java Updated as part of this pull request.
components/​abstractions/​src/​main/​java/​com/​microsoft/​kiota/​serialization/​ParseNodeFactoryRegistry.java Updated as part of this pull request.
components/​abstractions/​src/​main/​java/​com/​microsoft/​kiota/​ClientException.java Updated as part of this pull request.
components/​abstractions/​spotBugsExcludeFilter.xml Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

Resolved since last review (1)

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Sep 21, 2026
@baywet
Vincent Biret (baywet) merged commit 8712aa7 into microsoft:main Sep 21, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

com.microsoft.kiota.serialization.ParseNodeFactoryRegistry throws RuntimeException if service returns status code 503 with unexpected content type

3 participants