     req = :cowboy_req.set_resp_body("{}", req)
     {true, req, nil}
   end
+
+  @doc false
+  defp invalid_data_size_json(payload_limit) do
+    JSX.encode!(%{error: "Data key must be smaller than #{payload_limit}B"})
+  end
 end

    {authorized, req, state}
  end

  @invalid_data_size_json JSX.encode!(%{error: "Data key must be smaller than 10KB"})

  @doc """
  The event data can't be greater than 10KB
  """
  def valid_entity_length(req, %{event: event} = state) do
    {:ok, payload_limit} = Application.fetch_env(:poxa, :payload_limit)

    req = if valid do
            req
          else
            :cowboy_req.set_resp_body(invalid_data_size_json(payload_limit), req)
          end
    {valid, req, state}
  end
