Skip to content

Commit 1659212

Browse files
committed
Error converters need to be public so they can be used in other project's serializercontexts
1 parent fa56eae commit 1659212

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/Elastic.Transport/Components/Serialization/Converters/ErrorCauseConverter.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212

1313
namespace Elastic.Transport;
1414

15-
internal class ErrorCauseConverter : ErrorCauseConverter<ErrorCause> { }
15+
/// A JSON converter for <see cref="ErrorCause"/>
16+
public class ErrorCauseConverter : ErrorCauseConverter<ErrorCause> { }
1617

17-
internal class ErrorConverter : ErrorCauseConverter<Error>
18+
/// A JSON converter for <see cref="Error"/>
19+
public class ErrorConverter : ErrorCauseConverter<Error>
1820
{
21+
/// <inheritdoc cref="ErrorCauseConverter{T}.ReadMore"/>
1922
protected override bool ReadMore(ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName, Error errorCause)
2023
{
2124
void ReadAssign<T>(ref Utf8JsonReader r, Action<Error, T> set) =>
@@ -36,16 +39,16 @@ void ReadAssign<T>(ref Utf8JsonReader r, Action<Error, T> set) =>
3639
}
3740
}
3841

39-
internal class ErrorCauseConverter<TErrorCause> : JsonConverter<TErrorCause> where TErrorCause : ErrorCause, new()
42+
/// A JSON converter for <see cref="ErrorCause"/> implementations
43+
public abstract class ErrorCauseConverter<TErrorCause> : JsonConverter<TErrorCause> where TErrorCause : ErrorCause, new()
4044
{
45+
/// <inheritdoc cref="JsonConverter{T}.Read"/>
4146
public override TErrorCause Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
4247
{
4348
if (reader.TokenType != JsonTokenType.StartObject)
44-
{
4549
return reader.TokenType == JsonTokenType.String
4650
? new TErrorCause { Reason = reader.GetString() }
4751
: null;
48-
}
4952

5053
var errorCause = new TErrorCause();
5154
var additionalProperties = new Dictionary<string, object>();
@@ -176,8 +179,10 @@ private static IReadOnlyCollection<string> ReadSingleOrCollection(ref Utf8JsonRe
176179
}
177180
}
178181

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

185+
/// <inheritdoc cref="JsonConverter{T}.Read"/>
181186
public override void Write(Utf8JsonWriter writer, TErrorCause value, JsonSerializerOptions options)
182187
{
183188
writer.WriteStartObject();

src/Elastic.Transport/DistributedTransport.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public sealed class DistributedTransport(ITransportConfiguration configuration)
2929
{
3030
}
3131

32-
/// <inheritdoc cref="ITransport{TConfiguration}" />
32+
/// <summary>
33+
/// Transport coordinates the client requests over the node pool nodes and is in charge of falling over on
34+
/// different nodes
35+
/// </summary>
3336
public class DistributedTransport<TConfiguration> : ITransport<TConfiguration>
3437
where TConfiguration : class, ITransportConfiguration
3538
{

src/Elastic.Transport/Products/Elasticsearch/ErrorSerializationContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ namespace Elastic.Transport.Products.Elasticsearch;
1111
/// Adds support for serializing Elasticsearch errors using <see cref="IJsonTypeInfoResolver"/>
1212
[JsonSerializable(typeof(Error))]
1313
[JsonSerializable(typeof(ErrorCause))]
14+
[JsonSerializable(typeof(ElasticsearchServerError))]
15+
[JsonSerializable(typeof(ElasticsearchResponse))]
1416
public partial class ErrorSerializerContext : JsonSerializerContext;

src/Elastic.Transport/Products/Elasticsearch/Failures/Error.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public override string ToString() => CausedBy == null
3333
: $"Type: {Type} Reason: \"{Reason}\" CausedBy: \"{CausedBy}\"";
3434
}
3535

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

132-
public override void Write(Utf8JsonWriter writer, Error value, JsonSerializerOptions options) => throw new NotImplementedException();
134+
/// <inheritdoc cref="JsonConverter{T}.Read"/>
135+
public override void Write(Utf8JsonWriter writer, Error value, JsonSerializerOptions options) =>
136+
throw new NotImplementedException();
133137
}

0 commit comments

Comments
 (0)