Skip to content

Commit 6dff067

Browse files
committed
feat(controllers): add singular Error method
1 parent 38f15c3 commit 6dff067

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Linq;
23
using JsonApiDotNetCore.Internal;
34
using Microsoft.AspNetCore.Mvc;
@@ -16,6 +17,17 @@ protected IActionResult Forbidden()
1617
return new StatusCodeResult(403);
1718
}
1819

20+
protected IActionResult Error(Error error)
21+
{
22+
var errorCollection = new ErrorCollection {
23+
Errors = new List<Error> { error }
24+
};
25+
var result = new ObjectResult(errorCollection);
26+
result.StatusCode = error.StatusCode;
27+
28+
return result;
29+
}
30+
1931
protected IActionResult Errors(ErrorCollection errors)
2032
{
2133
var result = new ObjectResult(errors);
@@ -27,7 +39,7 @@ protected IActionResult Errors(ErrorCollection errors)
2739
private int GetErrorStatusCode(ErrorCollection errors)
2840
{
2941
var statusCodes = errors.Errors
30-
.Select(e => (int)e.StatusCode)
42+
.Select(e => e.StatusCode)
3143
.Distinct()
3244
.ToList();
3345

0 commit comments

Comments
 (0)