Open ipolevoy opened 1 year ago
One idea is to add a configuration to the AppControllerConfig to configure some SystemErrorController, so that such a controller would get the error generated, but would be in a full control of a response - either direct or using a view.
A better idea is to:
public class RouteConfig extends AbstractRouteConfig {
@Override
public void init(AppContext appContext) {
....
routeError().to(SystemErrorController.class).action("renderError");
.....
}
}
Include the SystemErrorController into the framework by default. This way, if there is a route to it, it will and the controller will look like this:
public SystemErrorController extends AppController{
public void renderError(){
Exception getException(); // - special method to get the exception that actually happened
}
}
In case there is a routing error with this controller (say method missing), the usual system default behavior triggers.
The SystemErrorController will have access to all request parameters and will be able to render the response directly or via a view just like any other controller. It will also be able to set response code, and any header, including Content-type, so that the API - only-based apps can respond to internal errors in JSON, XML format and content.
add documentation to the site
Currently, if there is a system error and there is no route to execute, the
renderSystemError(..)
method is called:https://github.com/javalite/javalite/blob/3dc111a0658b9ffc132bcc7565001beb976eff20/activeweb/src/main/java/org/javalite/activeweb/RequestDispatcher.java#L250
However, it renders an HTML error by default and the application developer has no control over this process.
A proposal is to implement the ability for an application developer to have full control over the error response. For example, while building a JSON-based API app, responding with HTML is making no sense.