Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/usage/errors.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Errors

Errors returned will contain only the properties that are set on the `Error` class. Custom fields can be added through `Error.Meta`.
You can create a custom error by throwing a `JsonApiException` (which accepts an `Error` instance), or returning an `Error` instance from an `ActionResult` in a controller.
Please keep in mind that JSON:API requires Title to be a generic message, while Detail should contain information about the specific problem occurence.
Errors returned will contain only the properties that are set on the `ErrorObject` class. Custom fields can be added through `ErrorObject.Meta`.
You can create a custom error by throwing a `JsonApiException` (which accepts an `ErrorObject` instance), or returning an `ErrorObject` instance from an `ActionResult` in a controller.
Please keep in mind that JSON:API requires `Title` to be a generic message, while `Detail` should contain information about the specific problem occurence.

From a controller method:

```c#
return Conflict(new Error(HttpStatusCode.Conflict)
return Conflict(new ErrorObject(HttpStatusCode.Conflict)
{
Title = "Target resource was modified by another user.",
Detail = $"User {userName} changed the {resourceField} field on {resourceName} resource."
Expand All @@ -17,7 +17,7 @@ return Conflict(new Error(HttpStatusCode.Conflict)
From other code:

```c#
throw new JsonApiException(new Error(HttpStatusCode.Conflict)
throw new JsonApiException(new ErrorObject(HttpStatusCode.Conflict)
{
Title = "Target resource was modified by another user.",
Detail = $"User {userName} changed the {resourceField} field on {resourceName} resource."
Expand Down Expand Up @@ -75,7 +75,7 @@ public class CustomExceptionHandler : ExceptionHandler
{
return new[]
{
new Error(HttpStatusCode.Conflict)
new ErrorObject(HttpStatusCode.Conflict)
{
Title = "Product is temporarily available.",
Detail = $"Product {productOutOfStock.ProductId} " +
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/extensibility/resource-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class EmployeeDefinition : JsonApiResourceDefinition<Employee, int>
if (existingIncludes.Any(include =>
include.Relationship.Property.Name == nameof(Employee.Manager)))
{
throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Including the manager of employees is not permitted."
});
Expand Down