alpaca-trade-api-csharp
alpaca-trade-api-csharp copied to clipboard
Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
I'm suddenly getting this error when using the latest prerelease version. The line 2070 that it references at is Console.WriteLine(ex.Message)
Full stacktrace:
Exception Type:
Alpaca.Markets.RestClientErrorException
Exception Message:
Internal Server Error
Exception StackTrace:
at Alpaca.Markets.HttpResponseMethodExtensions.DeserializeAsync[TApi,TJson](HttpResponseMessage response)
at Alpaca.Markets.HttpResponseMethodExtensions.DeserializeAsync[TApi,TJson](HttpResponseMessage response)
at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpRequestMessage request, CancellationToken cancellationToken)
at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpMethod method, Uri endpointUri, CancellationToken cancellationToken)
at OoplesFinanceAdminClient.AlpacaApi.GetTopLevelInfo() in E:\OoplesFinanceAdminClient\OoplesFinanceAdminClient\AlpacaApi.cs:line 2070
Exception Target Site:
MoveNext
Exception Source:
Alpaca.Markets
Exception HResult:
-2146233088
Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at Alpaca.Markets.HttpResponseMethodExtensions.getException(HttpResponseMessage response, JsonReader reader)
Expected Behavior
No response
Steps To Reproduce
No response
Environment
SDK Version: 6.0.6
OS (version, bitness): Windows 10
.NET SDK (version): 6.0
target process .NET version/bitness: 6.0 x64
Anything else?
No response
It's not an error in SDK. The server returns the HTTP 500 status and HTML body. The SDK tries to parse response content but has no success - the resulting exception contains information about the original HTTP response and parsing failure. But I agree - in most cases, users just want to see the HTTP-related error this case so in the next versions of SDK I'll change the approach for throwing exceptions in such cases.
@ooples This change can be tested in versions 5.3.6 and 6.0.1-beta1 of the SDK.
I'll close it for now. You can re-open it if the problem wasn't resolved on your side.