renderError method

Future<String> renderError(
  1. int status, {
  2. Map<String, Object?> params = const {},
  3. String message = '',
  4. bool toData = false,
})

Renders an error view with the specified status and parameters.

This method handles setting error-related parameters and generating the appropriate error view based on the status and other parameters.

status - The HTTP status code for the error. params - Optional map of additional parameters to be added. Default is an empty map. message - Optional error message to be included. Default is an empty string. toData - Flag indicating whether to include the success parameter in the response. Default is false.

Returns a Future<String> containing the rendered error view.

Implementation

Future<String> renderError(
  int status, {
  Map<String, Object?> params = const {},
  String message = '',
  bool toData = false,
}) {
  if (message.isNotEmpty) {
    addParam('error', message);
  } else if (toData && !hasParam('success')) {
    if (!hasParam('message')) {
      addParam('message', status == 404 ? 'error.notfound' : 'error.$status');
    }
    addParam('success', false);
  }

  if (Console.isDebug) {
    addParams(params);
  }

  addParam('status', status);

  return renderView(
    path: ErrorWidget().layout,
    status: status,
    isFile: false,
    toData: toData,
  );
}