2929using System . Threading ;
3030using Seq . Api . Streams ;
3131using System . Net . WebSockets ;
32+ using Seq . Api . Model . Shared ;
3233
3334namespace Seq . Api . Client
3435{
@@ -42,7 +43,7 @@ public sealed class SeqApiClient : IDisposable
4243 // Future versions of Seq may not completely support vN-1 features, however
4344 // providing this as an Accept header will ensure what compatibility is available
4445 // can be utilized.
45- const string SeqApiV10MediaType = "application/vnd.datalust.seq.v10 +json" ;
46+ const string SeqApiV11MediaType = "application/vnd.datalust.seq.v11 +json" ;
4647
4748 readonly CookieContainer _cookies = new ( ) ;
4849 readonly JsonSerializer _serializer = JsonSerializer . Create (
@@ -111,7 +112,7 @@ public SeqApiClient(string serverUrl, string apiKey = null, Func<CookieContainer
111112
112113 HttpClient = new HttpClient ( httpMessageHandler ) ;
113114 HttpClient . BaseAddress = new Uri ( baseAddress ) ;
114- HttpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( SeqApiV10MediaType ) ) ;
115+ HttpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( SeqApiV11MediaType ) ) ;
115116
116117 if ( _apiKey != null )
117118 HttpClient . DefaultRequestHeaders . Add ( "X-Seq-ApiKey" , _apiKey ) ;
@@ -372,23 +373,25 @@ async Task<string> HttpGetStringAsync(string url, CancellationToken cancellation
372373 async Task < Stream > HttpSendAsync ( HttpRequestMessage request , CancellationToken cancellationToken = default )
373374 {
374375 var response = await HttpClient . SendAsync ( request , cancellationToken ) . ConfigureAwait ( false ) ;
376+ // ReSharper disable once MethodSupportsCancellation
375377 var stream = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
376378
377379 if ( response . IsSuccessStatusCode )
378380 return stream ;
379381
380- Dictionary < string , object > payload = null ;
382+ ErrorPart error = null ;
381383 try
382384 {
383- payload = _serializer . Deserialize < Dictionary < string , object > > ( new JsonTextReader ( new StreamReader ( stream ) ) ) ;
385+ error = _serializer . Deserialize < ErrorPart > ( new JsonTextReader ( new StreamReader ( stream ) ) ) ;
384386 }
385387 // ReSharper disable once EmptyGeneralCatchClause
386388 catch { }
387389
388- if ( payload != null && payload . TryGetValue ( "Error" , out var error ) && error != null )
389- throw new SeqApiException ( $ "{ ( int ) response . StatusCode } - { error } ", response . StatusCode ) ;
390+ var exceptionMessage = $ "The Seq request failed ({ ( int ) response . StatusCode } /{ response . StatusCode } ).";
391+ if ( error ? . Error != null )
392+ exceptionMessage += $ " { error . Error } ";
390393
391- throw new SeqApiException ( $ "The Seq request failed ( { ( int ) response . StatusCode } / { response . StatusCode } )." , response . StatusCode ) ;
394+ throw new SeqApiException ( exceptionMessage , response . StatusCode ) ;
392395 }
393396
394397 HttpContent MakeJsonContent ( object content )
0 commit comments