Skip to content

Server errors get reported as BadRequest #24

Description

@ivankom82

When a server response does not contain json, it is failed to parse inside Forge.AI and gets translated into BadRequest which it isn't.
Is it possible to retain the original response code at least? See the attached snippet for 504 on gateway timeout.

2025/06/10 13:15:06.351|0059|Info| [System.Net.Http.HttpClient.Forge.OpenAI.ClientHandler] Received HTTP response headers after 900479.5136ms - 504 2025/06/10 13:15:06.351|0059|Info| [System.Net.Http.HttpClient.Forge.OpenAI.LogicalHandler] End processing HTTP request after 900479.5991ms - 504 2025/06/10 13:15:06.352|0059|Debg| [Forge.OpenAI.Infrastructure.ApiHttpService] ApiCall, response arrived from baseAddress: https://api.openai.com/, uri: https://api.openai.com/v1/audio/transcriptions, method: POST 2025/06/10 13:15:06.352|0059|Debg| [Forge.OpenAI.Infrastructure.ApiHttpService] ApiCall, response indicates an unsuccessful operation from https://api.openai.com/https://api.openai.com/v1/audio/transcriptions, method: POST 2025/06/10 13:15:06.369|0059|Erro| [Forge.OpenAI.Infrastructure.ApiHttpService] 'e' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. System.Text.Json.JsonException: 'e' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: 'e' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex) at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 json, JsonTypeInfo1 jsonTypeInfo)
at Forge.OpenAI.Models.Common.HttpOperationResult..ctor(Exception exception, HttpStatusCode httpStatusCode, String errorMessage)
at Forge.OpenAI.Infrastructure.ApiHttpService.<>c__DisplayClass27_02.<<ApiCall>b__0>d.MoveNext() --- End of stack trace from previous location --- at Forge.OpenAI.Infrastructure.ApiHttpService.ErrorHandlerContextAsync[TResult](Func2 func, CancellationToken cancellationToken)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions