Skip to content

Commit

Permalink
Merge pull request #25 from Byndyusoft/feautue/forbidden
Browse files Browse the repository at this point in the history
Добавлена общая ошибка Forbidden
  • Loading branch information
Mblkolo authored Jun 25, 2024
2 parents 8c1f8fc + bed3350 commit ba0c918
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.3.0</Version>
<Version>1.4.0</Version>
<RootNamespace>Byndyusoft.ModelResult</RootNamespace>
<Authors>Byndyusoft</Authors>
<PackageTags>Byndyusoft;ModelResult</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ private static ActionResult GetErrorResult(ModelResult modelResult)
if (modelResult.IsNotFound())
return new NotFoundResult();

if (modelResult.IsForbidden())
return new ForbidResult();

return new BadRequestObjectResult(modelResult.GetError());
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/ModelResult/Common/CommonErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public static class CommonErrorCodes
{
public static string NotFound => "Common.NotFound";

public static string Forbidden => "Common.Forbidden";
}
}
2 changes: 2 additions & 0 deletions src/ModelResult/Common/CommonErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public static class CommonErrorMessages
{
public static string NotFound => "Not found";

public static string Forbidden => "Forbidden";
}
}
2 changes: 2 additions & 0 deletions src/ModelResult/Common/CommonErrorResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
public static class CommonErrorResult
{
public static ErrorModelResult NotFound { get; } = new ErrorModelResult(CommonErrorCodes.NotFound, CommonErrorMessages.NotFound);

public static ErrorModelResult Forbidden { get; } = new ErrorModelResult(CommonErrorCodes.Forbidden, CommonErrorMessages.Forbidden);
}
}
10 changes: 10 additions & 0 deletions src/ModelResult/Common/CommonErrorResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ public static bool IsNotFound(this ModelResult modelResult)
return modelResult.IsError() && modelResult.GetError().Code == CommonErrorCodes.NotFound;
}

public static bool IsForbidden(this ModelResult modelResult)
{
return modelResult.IsError() && modelResult.GetError().Code == CommonErrorCodes.Forbidden;
}

public static bool IsNotFound<T>(this ModelResult<T> modelResult)
{
return IsNotFound(modelResult.AsSimple());
}

public static bool IsForbidden<T>(this ModelResult<T> modelResult)
{
return IsForbidden(modelResult.AsSimple());
}
}
}

0 comments on commit ba0c918

Please sign in to comment.