setReason method

  1. @override
void setReason(
  1. String message
)
override

Sets the HTTP detailed reason for this response.

This method updates the response's message, allowing the server to indicate success, client errors, server errors, or any other relevant reason why the response is what it is, to the client.

Example:

// Respond with a success message
responseProvider.setReason("Request is success");

// Respond with a client error
responseProvider.setReason("Something happened");

message – A string representing the desired message to be sent.

Implementation

@override
void setReason(String message) {
  if (isCommitted()) {
    throw ResponseAlreadyCommittedException('Cannot set message: response has already been committed', uri: _request.getUri());
  }

  _response.reasonPhrase = message;
}