internalServerError method

Future<void> internalServerError({
  1. Object? data,
  2. Object? exception,
})

use data => if you want to add more details to the client side use it use exception => if you want to display the exception BUT ! it will be sent to client side in debug mode only

Implementation

Future<void> internalServerError({
  Object? data,
  Object? exception,
}) async {
  try {
    /// set the Response contentType to Json
    response.headers.contentType = io.ContentType.json;

    /// set the status code to 500
    response.statusCode = io.HttpStatus.internalServerError;

    response.write(toJson(
      {
        'status_code': io.HttpStatus.internalServerError,
        'message': 'Internal Server Error',
        if (data != null) 'data': data,
        if (exception != null) 'exception': exception
        // if (exception != null && !isInProduction) 'exception': exception
      },
    ));
    // ignore: empty_catches
  } catch (e) {}
}