Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

namespace Elastic.Transport;

internal class ErrorCauseConverter : ErrorCauseConverter<ErrorCause> { }
/// A JSON converter for <see cref="ErrorCause"/>
public class ErrorCauseConverter : ErrorCauseConverter<ErrorCause> { }

internal class ErrorConverter : ErrorCauseConverter<Error>
/// A JSON converter for <see cref="Error"/>
public class ErrorConverter : ErrorCauseConverter<Error>
{
/// <inheritdoc cref="ErrorCauseConverter{T}.ReadMore"/>
protected override bool ReadMore(ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName, Error errorCause)
{
void ReadAssign<T>(ref Utf8JsonReader r, Action<Error, T> set) =>
Expand All @@ -36,16 +39,16 @@ void ReadAssign<T>(ref Utf8JsonReader r, Action<Error, T> set) =>
}
}

internal class ErrorCauseConverter<TErrorCause> : JsonConverter<TErrorCause> where TErrorCause : ErrorCause, new()
/// A JSON converter for <see cref="ErrorCause"/> implementations
public abstract class ErrorCauseConverter<TErrorCause> : JsonConverter<TErrorCause> where TErrorCause : ErrorCause, new()
{
/// <inheritdoc cref="JsonConverter{T}.Read"/>
public override TErrorCause Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
return reader.TokenType == JsonTokenType.String
? new TErrorCause { Reason = reader.GetString() }
: null;
}

var errorCause = new TErrorCause();
var additionalProperties = new Dictionary<string, object>();
Expand Down Expand Up @@ -176,8 +179,10 @@ private static IReadOnlyCollection<string> ReadSingleOrCollection(ref Utf8JsonRe
}
}

/// Read additional properties for the particular <see cref="ErrorCause"/> implementation
protected virtual bool ReadMore(ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName, TErrorCause errorCause) => false;

/// <inheritdoc cref="JsonConverter{T}.Read"/>
public override void Write(Utf8JsonWriter writer, TErrorCause value, JsonSerializerOptions options)
{
writer.WriteStartObject();
Expand Down
5 changes: 4 additions & 1 deletion src/Elastic.Transport/DistributedTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public sealed class DistributedTransport(ITransportConfiguration configuration)
{
}

/// <inheritdoc cref="ITransport{TConfiguration}" />
/// <summary>
/// Transport coordinates the client requests over the node pool nodes and is in charge of falling over on
/// different nodes
/// </summary>
public class DistributedTransport<TConfiguration> : ITransport<TConfiguration>
where TConfiguration : class, ITransportConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ namespace Elastic.Transport.Products.Elasticsearch;
/// Adds support for serializing Elasticsearch errors using <see cref="IJsonTypeInfoResolver"/>
[JsonSerializable(typeof(Error))]
[JsonSerializable(typeof(ErrorCause))]
[JsonSerializable(typeof(ElasticsearchServerError))]
[JsonSerializable(typeof(ElasticsearchResponse))]
public partial class ErrorSerializerContext : JsonSerializerContext;
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public override string ToString() => CausedBy == null
: $"Type: {Type} Reason: \"{Reason}\" CausedBy: \"{CausedBy}\"";
}

internal sealed class ErrorConverter : JsonConverter<Error>
/// A JSON converter for <see cref="Error"/>.
public sealed class ErrorConverter : JsonConverter<Error>
{
/// <inheritdoc cref="JsonConverter{T}.Read"/>
public override Error Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
Expand Down Expand Up @@ -129,5 +131,7 @@ public override Error Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe
throw new JsonException("Could not deserialise the error response.");
}

public override void Write(Utf8JsonWriter writer, Error value, JsonSerializerOptions options) => throw new NotImplementedException();
/// <inheritdoc cref="JsonConverter{T}.Read"/>
public override void Write(Utf8JsonWriter writer, Error value, JsonSerializerOptions options) =>
throw new NotImplementedException();
}
Loading