Exception handling
The exceptions are globally handled in the ErrorFilterAttribute class.
Continuing the previous example, if we post a height = 0 into our http://server.localtest.me/headlessApi/TestPage endpoint, and then try to get the TestPage, we would get an invalid operation exception.
However, instead of a Internal Server Error, the HTTP status returned is a Invalid Operation.
The reason is, the exception is intercepted in the src\Litium.AddOns.HeadlessApi\Attributes\ErrorFilterAttribute.cs class, and re-wired as a BadRequest.
You should consider doing the same thing for known errors, as they are not server errors, rather unexpected data.
switch(actionExecutedContext.Exception)
{
//Here we treat known exceptions as BadRequests.
//these exceptions are not bugs in code, just that the original request is bad.
//TODO: handle other known exceptions.
case DoesNotExistException doesNotExistsException:
case InvalidOperationException invalidOperationException:
actionExecutedContext.Response = actionExecutedContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpError(actionExecutedContext.Exception, true));
return;
}