render method

dynamic render(
  1. Object error,
  2. HttpRequest req
)

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 IHttpException gets 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 the errors and the old input, and redirects back. See Session.flashErrors.
  • any other error gets 500 with {"code": "server_error", "message": "Server Error"}. When APP_ENV is development or local, 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;
}