response property

Response get response

Use this to access the current response in the zone.

This can be useful when you need to access the response in a service or controller that is not directly called by the router.

The response is stored in the zone when the request is processed by the router. Therefore, you can access the response in all services and controllers that are called by the router.

If you need to access the response in a service or controller that is called outside of the response scope, you need to provide the response instance to the service or controller.

Throws MissingResponseContextException if no response context is available.

Implementation

static Response get response {
  if (!ServerContext.hasContext) {
    throw MissingResponseContextException();
  }
  final res = ServerContext.current.response;
  if (res == null) {
    throw MissingResponseContextException();
  }
  return res;
}