Skip to content

Commit

Permalink
Fixes #372 (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev authored Sep 10, 2024
1 parent 075af2e commit 6175f3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (C) Ubiquitous AS. All rights reserved
// Licensed under the Apache License, Version 2.0.

// ReSharper disable once CheckNamespace

using Eventuous.Extensions.AspNetCore;

// ReSharper disable once CheckNamespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Http;
using static Microsoft.AspNetCore.Http.StatusCodes;

// ReSharper disable once CheckNamespace
namespace Eventuous.Extensions.AspNetCore;

static class ResultExtensions {
Expand Down Expand Up @@ -37,22 +38,16 @@ static IResult AsValidationProblem(Result<TState>.Error error, int statusCode)
}
);

static ActionResult AsProblem(Result<TState>.Error error, int statusCode) => new ObjectResult(CreateResult(error, new ProblemDetails(), statusCode));
static ActionResult AsProblem(Result<TState>.Error error, int statusCode) => CreateResult(error, new ProblemDetails(), statusCode);

static ActionResult AsValidationProblem(Result<TState>.Error error, int statusCode)
=> CreateResult(error, new ValidationProblemDetails(error.AsErrors()), statusCode);

static ActionResult CreateResult<T>(Result<TState>.Error error, T details, int statusCode) where T : ProblemDetails {
details.Status = statusCode;
details.Title = error.ErrorMessage;
details.Detail = error.Exception?.ToString();
details.Type = error.Exception?.GetType().Name;

return new ObjectResult(details) {
StatusCode = Status400BadRequest,
static ActionResult CreateResult<T>(Result<TState>.Error error, T details, int statusCode) where T : ProblemDetails
=> new ObjectResult(PopulateDetails(details, error, statusCode)) {
StatusCode = statusCode,
ContentTypes = [ContentTypes.ProblemDetails]
};
}
}

static T PopulateDetails<T, TState>(T details, Result<TState>.Error error, int statusCode) where T : ProblemDetails where TState : State<TState>, new() {
Expand Down

0 comments on commit 6175f3f

Please sign in to comment.