Skip to content

Commit

Permalink
v2.0.0-preview.1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ogulcanturan committed Oct 28, 2024
1 parent 36b732d commit 9e87e27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Ogu.Response.Json/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static IJsonResponse ToJsonResponse(this Exception exception, bool includ
return HttpStatusCode.InternalServerError.ToFailureJsonResponse(exception, includeTraces, serializerOptions);
}

public static IJsonResponse ToJsonResponse(this Exception[] exceptions, bool includeTraces, JsonSerializerOptions serializerOptions = null)
public static IJsonResponse ToJsonResponse(this Exception[] exceptions, bool includeTraces = false, JsonSerializerOptions serializerOptions = null)
{
return HttpStatusCode.InternalServerError.ToFailureJsonResponse(exceptions, includeTraces, serializerOptions);
}
Expand All @@ -22,12 +22,12 @@ public static IJsonResponse<TData> ToJsonResponse<TData>(this Exception exceptio
return HttpStatusCode.InternalServerError.ToFailureJsonResponse<TData>(exception, includeTraces, serializerOptions);
}

public static IJsonResponse<TData> ToJsonResponse<TData>(this Exception[] exceptions, bool includeTraces, JsonSerializerOptions serializerOptions = null)
public static IJsonResponse<TData> ToJsonResponse<TData>(this Exception[] exceptions, bool includeTraces = false, JsonSerializerOptions serializerOptions = null)
{
return HttpStatusCode.InternalServerError.ToFailureJsonResponse<TData>(exceptions, includeTraces, serializerOptions);
}

public static IError ToJsonError(this Exception exception, bool includeTraces)
public static IError ToJsonError(this Exception exception, bool includeTraces = false)
{
return new JsonError(exception, includeTraces);
}
Expand Down
22 changes: 13 additions & 9 deletions src/Ogu.Response.Json/JsonErrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,26 @@ public static Exception ToException(this IError error)
}

/// <summary>
/// Converts a list of <see cref="IError"/> instances to a single <see cref="Exception"/>.
/// Converts a list of <see cref="IError"/> instances to a single <see cref="Exception"/>.
/// </summary>
/// <param name="errors">The list of <see cref="IError"/> objects to convert. Each error represents an issue
/// that can be transformed into an <see cref="Exception"/>.</param>
/// <param name="errors">
/// The list of <see cref="IError"/> objects to convert. Each error represents an issue
/// that can be transformed into an <see cref="Exception"/>.</param>
/// <returns>
/// An <see cref="AggregateException"/> containing exceptions created from each <see cref="IError"/>
/// if the list contains any errors; otherwise, <c>null</c>.
/// An <see cref="AggregateException"/> containing exceptions created from each <see cref="IError"/>
/// if the list contains any errors; otherwise, <c>null</c>.
/// </returns>
/// <remarks>
/// If there are no errors in the provided list, this method returns <c>null</c>.
/// If there are no errors in the provided list, this method returns <c>null</c>.
/// </remarks>
public static Exception ToException(this List<IError> errors)
{
return errors.Count > 0
? new AggregateException(errors.Select(error => error.ToException()))
: null;
switch (errors.Count)
{
case 0: return null;
case 1: return errors[0].ToException();
default: return new AggregateException(errors.Select(error => error.ToException()));
}
}
}
}
4 changes: 2 additions & 2 deletions src/Ogu.Response.Json/JsonResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static IJsonResponse ToFailureJsonResponse(this HttpStatusCode status, Ex

public static IJsonResponse ToFailureJsonResponse(this HttpStatusCode status, Exception[] exceptions, bool includeTraces = false, JsonSerializerOptions serializerOptions = null)
{
return JsonResponse.Failure(status, exceptions?.Where(e => e != null).SelectMany(e => GetErrors(e, includeTraces)).ToList(), serializerOptions);
return JsonResponse.Failure(status, exceptions.SelectMany(e => GetErrors(e, includeTraces)).ToList(), serializerOptions);
}

public static IJsonResponse ToFailureJsonResponse(this HttpStatusCode status, string error, JsonSerializerOptions serializerOptions = null)
Expand All @@ -83,7 +83,7 @@ public static IJsonResponse ToFailureJsonResponse(this HttpStatusCode status, st

public static IJsonResponse ToFailureJsonResponse(this HttpStatusCode status, string[] errors, JsonSerializerOptions serializerOptions = null)
{
return JsonResponse.Failure(status, errors?.Where(e => e != null).Select(e => (IError)new JsonError(e)).ToList(), serializerOptions);
return JsonResponse.Failure(status, errors.Select(e => (IError)new JsonError(e)).ToList(), serializerOptions);
}

private static List<IError> GetErrors(Exception exception, bool includeTraces)
Expand Down
4 changes: 2 additions & 2 deletions src/Ogu.Response.Json/JsonResponseTExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static IJsonResponse<TData> ToFailureJsonResponse<TData>(this HttpStatusC

public static IJsonResponse<TData> ToFailureJsonResponse<TData>(this HttpStatusCode status, Exception[] exceptions, bool includeTraces = false, JsonSerializerOptions serializerOptions = null)
{
return JsonResponse<TData>.Failure(status, exceptions?.Where(e => e != null).Select(e => e.ToJsonError(includeTraces)).ToList(), serializerOptions);
return JsonResponse<TData>.Failure(status, exceptions.Select(e => e.ToJsonError(includeTraces)).ToList(), serializerOptions);
}

public static IJsonResponse<TData> ToFailureJsonResponse<TData>(this HttpStatusCode status, string error, JsonSerializerOptions serializerOptions = null)
Expand All @@ -100,7 +100,7 @@ public static IJsonResponse<TData> ToFailureJsonResponse<TData>(this HttpStatusC

public static IJsonResponse<TData> ToFailureJsonResponse<TData>(this HttpStatusCode status, string[] errors, JsonSerializerOptions serializerOptions = null)
{
return JsonResponse<TData>.Failure(status, errors?.Where(e => e != null).Select(e => (IError)new JsonError(e)).ToList(), serializerOptions);
return JsonResponse<TData>.Failure(status, errors.Select(e => (IError)new JsonError(e)).ToList(), serializerOptions);
}
}
}

0 comments on commit 9e87e27

Please sign in to comment.