code: func writeError(c context.Context, w http.ResponseWriter, err error) {
  	var code codes.Code
  	var httpStatus int
  	var msg string
  	if perr, ok := err.(*protocolError); ok {
  		code = codes.InvalidArgument
  		msg = perr.err.Error()
  		httpStatus = perr.status
  	} else {
  		code = errorCode(err)
  		msg = grpc.ErrorDesc(err)
  		httpStatus = grpcutil.CodeStatus(code)
  	}
  
  	body := msg
  	level := logging.Warning
  	if httpStatus >= 500 {
  		level = logging.Error
  		// Hide potential implementation details from the user.
  		body = http.StatusText(httpStatus)
  	}
  	logging.Logf(c, level, "prpc: responding with %s error: %s", code, msg)
  
  	w.Header().Set(HeaderGRPCCode, strconv.Itoa(int(code)))
  	w.Header().Set(headerContentType, "text/plain")
  	w.WriteHeader(httpStatus)
  	if _, err := io.WriteString(w, body); err != nil {
  		logging.WithError(err).Errorf(c, "prpc: failed to write response body")
  		// The header is already written. There is nothing more we can do.
  		return
  	}
  	io.WriteString(w, "\n")
  }
docs: // writeError writes err to w and logs it.