microsoft / microsoft/kiota-java

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

Open
#1,683 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement type:enhancement
Dominant language
Java
Stars
38
Forks
34
Avg merge
15h 9m
Merged PRs (30d)
20

Description

Situation and background:
The Microsoft Graph API had some issues some days ago, where some calls to the API would return HTTP status code 503, with some html error message.

During this time, our use of the Graph API SDK, which in turn uses Kiota, lead to several application level crashes, because of uncaught RuntimeExceptions was propagated up the call stack from Kiota.

My observations, based on my understanding of the code:
The source of the exception, ParseNodeFactoryRegistry method getParseNode will attempt to find a parser for an expected content type.
In the case of Graph API, we expect JSON, so we only set up factories to handle that.

When the Graph API has an issue/downtime/whathaveyou, the method finds no factory to handle the response, and throws a RuntimeException directly.

Straight forward, I feel theres' two possible solutions.
1. Make getParseNode throw ApiException, which is a bit safer to try/catch than a pure "catch all" RuntimeException
2. Add a special case content type text/html factory that handles special error page responses, which might be in scope only for the graph api sdk.

With limited knowledge of how easy a custom factory is as an end user of MS Graph SDK, we feel forced to stop catching ApiException, and start catching RuntimeExceptions instead, hoping that no other runtime exceptions gets thrown and swallowed by our logic.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ParseNodeFactoryRegistry.getParseNode and trace how an unexpected text/html response is handled when only a JSON factory is registered. Reproduce the 503 response path and inspect the surrounding exception-handling tests, if present. Done means the behavior is defined for this response without forcing callers to catch an unrestricted RuntimeException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.