renderError function

dynamic renderError(
  1. HttpRequest req,
  2. Object error,
  3. StackTrace stackTrace
)

Report error and give the response for it, from the ExceptionHandler of AppConfig. It is not sent yet.

Implementation

dynamic renderError(HttpRequest req, Object error, StackTrace stackTrace) {
  /// `schema.parse()` in a controller: answer 422 like `req.validate()`
  if (error is dv.ValidationException) {
    error = ValidationException(message: error.errors);
  }
  ExceptionHandler handler = Dox().config.exceptionHandler;
  dynamic payload = error;
  try {
    if (error is! IHttpException) handler.report(error, stackTrace);
    payload = handler.render(error, req);
  } catch (handlerError, handlerStack) {
    /// a broken handler must not leave the client waiting.
    /// send the default answer for the first error.
    Logger.danger('ExceptionHandler failed: $handlerError\n$handlerStack');
  }
  return payload;
}