anasfik / openai

Dart/Flutter SDK for ChatGPT and all OpenAI APIs (GPT, Dall-e..)
https://pub.dev/packages/dart_openai
MIT License
591 stars 184 forks source link

why createStream silently ignored the potenital json decode error ? #190

Open JunYang-tes opened 3 months ago

JunYang-tes commented 3 months ago

Hi,

I'm wondering why this potienital json decode be ignored:

https://github.com/anasfik/openai/blob/650ffbf93961962fec1554ba817c07d9700e2002/lib/src/core/networking/client.dart#L390-L392

I'm using a Microsoft Azure provided openai services behand a cloudflare worker. when I misspelled the model name, I got a 403 response which body is not a valid json. In this case,I am unable to get either the data or the error message.

Is it possible to change here to this:

                try {
                  decodedData = decodeToMap(respondData);
                } catch (error) {
                  final statusCode = respond.statusCode;
                  final exception = RequestFailedException(error.toString(), statusCode);
                  yield* Stream<T>.error(exception);
                }