You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, errors will only contain the properties defined by the internal [Error](https://github.com/Research-Institute/json-api-dotnet-core/blob/master/src/JsonApiDotNetCore/Internal/Error.cs) class. However, you can create your own by inheriting from `Error` and either throwing it in a `JsonApiException` or returning the error from your controller.
371
+
372
+
```chsarp
373
+
// custom error definition
374
+
public class CustomError : Error {
375
+
public CustomError(string status, string title, string detail, string myProp)
376
+
: base(status, title, detail)
377
+
{
378
+
MyCustomProperty = myProp;
379
+
}
380
+
public string MyCustomProperty { get; set; }
381
+
}
382
+
383
+
// throwing a custom error
384
+
public void MyMethod() {
385
+
var error = new CustomError("507", "title", "detail", "custom");
386
+
throw new JsonApiException(error);
387
+
}
388
+
389
+
// returning from controller
390
+
[HttpPost]
391
+
public override async Task<IActionResult> PostAsync([FromBody] MyEntity entity)
392
+
{
393
+
if(_db.IsFull)
394
+
return new ObjectResult(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry."));
395
+
396
+
// ...
397
+
}
398
+
```
399
+
367
400
## Tests
368
401
369
402
I am using DotNetCoreDocs to generate sample requests and documentation.
0 commit comments