Skip to content

Commit

Permalink
Merge pull request #186 from atc-net/feature/add-reason-to-forbidden-…
Browse files Browse the repository at this point in the history
…result

feat: Add optional reason to Forbidden Result when using ProblemDetails
  • Loading branch information
davidkallesen authored Oct 6, 2023
2 parents 04f74b0 + 3c3fff5 commit fbe4569
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ private static void AppendMethodContentWithProblemDetails(
sb.AppendLine(8, $"=> new {resultName}({nameof(Results.ResultFactory)}.{nameof(Results.ResultFactory.CreateContentResultWithProblemDetails)}(HttpStatusCode.Unauthorized, null));");
break;
case HttpStatusCode.Forbidden:
sb.AppendLine(4, $"public static {resultName} Forbidden()");
sb.AppendLine(8, $"=> new {resultName}({nameof(Results.ResultFactory)}.{nameof(Results.ResultFactory.CreateContentResultWithProblemDetails)}(HttpStatusCode.Forbidden, null));");
sb.AppendLine(4, $"public static {resultName} Forbidden(string? message = null)");
sb.AppendLine(8, $"=> new {resultName}({nameof(Results.ResultFactory)}.{nameof(Results.ResultFactory.CreateContentResultWithProblemDetails)}(HttpStatusCode.Forbidden, message));");
break;
case HttpStatusCode.NotFound:
sb.AppendLine(4, $"public static {resultName} NotFound(string? message = null)");
Expand Down Expand Up @@ -323,10 +323,6 @@ private static void AppendMethodContentWithoutProblemDetails(
sb.AppendLine(4, $"public static {resultName} Unauthorized()");
sb.AppendLine(8, $"=> new {resultName}(new UnauthorizedResult());");
break;
case HttpStatusCode.Forbidden:
sb.AppendLine(4, $"public static {resultName} Forbidden()");
sb.AppendLine(8, $"=> new {resultName}(new StatusCodeResult(StatusCodes.Status403Forbidden));");
break;
case HttpStatusCode.NotFound:
sb.AppendLine(4, $"public static {resultName} NotFound(string? message = null)");
sb.AppendLine(8, $"=> new {resultName}(new NotFoundObjectResult(message));");
Expand All @@ -335,6 +331,7 @@ private static void AppendMethodContentWithoutProblemDetails(
sb.AppendLine(4, $"public static {resultName} Conflict(string? error = null)");
sb.AppendLine(8, $"=> new {resultName}(new ConflictObjectResult(error));");
break;
case HttpStatusCode.Forbidden:
case HttpStatusCode.MethodNotAllowed:
case HttpStatusCode.InternalServerError:
case HttpStatusCode.NotImplemented:
Expand Down

0 comments on commit fbe4569

Please sign in to comment.