onError method

  1. @override
FutureOr<Response> onError(
  1. Message message,
  2. T exception,
  3. StackTrace stackTrace
)
override

Implementation

@override
FutureOr<Response> onError(
    Message message, T exception, StackTrace stackTrace) {
  var body = JsonBody({
    "exception": exception.toString(),
    "stack_trace": stackTrace.toString()
  });

  var statusCode = (exception is StyleException) ? exception.statusCode : 500;

  if (message is Response) {
    return message
      ..body = body
      ..statusCode = statusCode;
  } else {
    return (message as Request).response(body, statusCode: statusCode);
  }
}