The idea of exception handling in ABP is very clear. There are altogether five types of exception classes.
Abpinitializationexception is used to encapsulate exceptions that occur during ABP initialization, as long as the abpinitializationexception exception is thrown and no additional processing is required. Such anomalies are often required for maintenance personnel to intervene in the analysis.
The other four exceptions are centrally processed in Abpcontroller, and the processing is divided into two steps: one, the exception event is triggered by Eventbus, and the corresponding exception handler handles the exception. For Abpvalidationexception,userfriendlyexception and Abpauthorizationexception exceptions, the ABP converts the exception information to ErrorInfo, and returned to the client as either view or JSON.
abpexception: base class for all custom exception classes in the ABP.
userfriendlyexception: Inherits from the Abpexception class, implements the Ihaslogseverity interface. The user can encapsulate an exception that needs to be returned to the client through an instance of Userfriendlyexception.
The actual use of userfriendlyexception samples such as the next
Iexceptiontoerrorinfoconverter: Defines a method for converting exception to errorinfo. Also defines a pointer to a self-contained object next, the author's intention is to attempt to construct a chain of exceptiontoerrorinfoconverter instances in a chain of responsibility, where each instance is used to convert a type of exception to ErrorInfo. For now, however, the ABP does not implement this functionality in this way, but instead plugs all the functionality into a Defaulterrorinfoconverter class.
Defaulterrorinfoconverter: Implements the Abpvalidationexception, Userfriendlyexception and Abpauthorizationexception instances convert exception to ErrorInfo
Ierrorinfobuilder : Defines a method for building a iexceptiontoerrorinfoconverter responsibility chain and a method for converting exception to a errorinfo instance.
Errorinfobuilder: Implements the method defined in interface Ierrorinfobuilder. By constructing the Defaulterrorinfoconverter instance and calling the instance to complete the exception to errorinfo conversion.
Abpcontroller: Override the Onexception method to centralize abpvalidationexception, Where userfriendlyexception and abpauthorizationexception are abnormal. Note where the abpinitializationexception exception is not handled in the ABP, the system automatically terminates if an abpinitializationexception exception occurs.
mvcajaxresponse<tresult>,mvcajaxresponse: Used to encapsulate response information for AJAX requests. Inherits from Ajaxresponse<tresult>, adds a TargetUrl property, and does not override the method in the base class.
Abpjsonresult: Inherit from the Jsonresult of Newtonsoft. The JSON object used to serialize the CLR object to CamelCase.
Custom Exception Event handling functions
Back to ABP source Analysis series Articles Directory
ABP Source Code Analysis 47: Exception Handling in ABP