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

Add fallback method for HttpClient.Send on unsupported platforms #316

Merged
merged 3 commits into from
Aug 6, 2023

Conversation

Almis90
Copy link
Contributor

@Almis90 Almis90 commented Jul 3, 2023

In this commit, I have introduced error handling to manage the PlatformNotSupportedException that arises when calling HttpClient.Send in the PostAsStreamAsync method.

This exception occurs because of the HttpClient.Send method is not supported on certain platforms (in my case I was testing on MAUI, Mac Platform). To manage this, I have added a try-catch block to catch the PlatformNotSupportedException and then fall back to the SendRequestPreNet6 method, which uses HttpClient.SendAsync.

kayhantolga and others added 3 commits June 22, 2023 02:43
Addressed an issue related to the using statement that was trying to send a disposed HttpRequestMessage in the catch block
@Almis90 Almis90 changed the base branch from master to dev July 9, 2023 14:38
@kayhantolga
Copy link
Member

Do you have a sample repository that I can use to test this? I am wondering if the stream works with your changes. 🤔

@kayhantolga kayhantolga added the question Further information is requested label Jul 24, 2023
@Almis90
Copy link
Contributor Author

Almis90 commented Jul 24, 2023

Do you have a sample repository that I can use to test this? I am wondering if the stream works with your changes. 🤔

You can find a sample here: https://github.com/Almis90/OpenAI.HttpClientIssue

To run it you will need to add your API key in the MauiProgram.cs

After you click the send button you will see the exception in the application output.

@kayhantolga
Copy link
Member

Thanks a lot, I will take a look.

@kayhantolga kayhantolga merged commit d12a3bb into betalgo:dev Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants