render method
What to send for error. Return anything a controller can return:
a DoxResponse, a map, a string. Return error itself (the
default) for the default answer:
- an
IHttpExceptiongets its own status and{"code": ..., "message": ...}. Validation errors get 422. - a validation error on a request with a session
(
SessionMiddleware) that does not want JSON (a form post, an Inertia request) flashes theerrorsand the old input, and redirects back. SeeSession.flashErrors. - any other error gets 500 with
{"code": "server_error", "message": "Server Error"}. WhenAPP_ENVisdevelopmentorlocal, the error text is sent instead.
The responseHandler of AppConfig still runs after it.
Implementation
dynamic render(Object error, HttpRequest req) {
if (error is ValidationException) {
DoxRequest? doxReq = SessionMiddleware.requestOf(req);
if (doxReq != null && !doxReq.expectsJson()) {
doxReq.session.flashErrors(error.message, input: doxReq.all());
return back(doxReq);
}
}
return error;
}