Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle JsonException when deserializing answerJson #325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaliyaudagedara
Copy link

@jaliyaudagedara jaliyaudagedara commented Jun 7, 2024

Purpose

When the answerJson is not a JSON, provide a more informative message.

Example

image

Does this introduce a breaking change?

[ ] Yes
[x] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

{
answerObject = JsonSerializer.Deserialize<JsonElement>(answerJson);
}
catch (JsonException)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
catch (JsonException)
catch (JsonException je)

}
catch (JsonException)
{
throw new InvalidOperationException($"Unable to cast '{answerJson}' as JsonElement.");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new InvalidOperationException($"Unable to cast '{answerJson}' as JsonElement.");
throw new InvalidOperationException(
message: $"Unable to cast '{answerJson}' as JsonElement.",
innerException: je);

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.

2 participants