HttpResponse.error constructor

HttpResponse.error(
  1. HttpStatus status, [
  2. String? message
])

Create an error response

Implementation

factory HttpResponse.error(HttpStatus status, [String? message]) {
  final errorMessage = message ?? status.message;
  final body = utf8.encode(errorMessage);

  return HttpResponse(
    status: status,
    headers: {
      'content-type': 'text/plain; charset=utf-8',
      'content-length': body.length.toString(),
    },
    body: body,
  );
}