Class GlobalExceptionFilter
- Namespace
- Breeze.AspNetCore
- Assembly
- Breeze.AspNetCore.NetCore.dll
Filter to capture and return entity errors
public class GlobalExceptionFilter : IExceptionFilter, IFilterMetadata
- Inheritance
-
GlobalExceptionFilter
- Implements
- Inherited Members
Remarks
The response is an RFC 9457 "problem details" document. By default it also carries the
pre-3.0 Code, Message and EntityErrors members, so a breeze-client 2.x
or 3.0 application reads it unchanged: RFC 9457 section 3.2 permits extension members and
requires consumers to ignore ones they do not recognize, so the document is conformant with
them present. See IncludeLegacyErrorMembers.
Constructors
GlobalExceptionFilter()
Empty constructor
public GlobalExceptionFilter()
Properties
StatusCodeForException
Maps an exception to an HTTP status code; return null to accept the default of 500.
Recognizing a duplicate-key or foreign-key violation as 409 Conflict means reading a provider-specific error number - 2627, 2601 and 547 for SQL Server, SQLSTATE 23505 and 23503 for PostgreSQL - so it does not belong in this filter, which knows nothing about the database. Supply the mapping instead:
o.Filters.Add(new GlobalExceptionFilter {
StatusCodeForException = ex => ex.GetBaseException() is SqlException { Number: 2627 or 2601 or 547 }
? HttpStatusCode.Conflict : null
});
public Func<Exception, HttpStatusCode?>? StatusCodeForException { get; set; }
Property Value
Methods
OnException(ExceptionContext)
Process exceptions to extract EntityErrors and include them in the response
public void OnException(ExceptionContext context)
Parameters
contextExceptionContext