From d8c17361f16530acce75edc157a8c107fd883a63 Mon Sep 17 00:00:00 2001 From: Tony Dang Date: Thu, 29 Aug 2024 14:18:09 -0700 Subject: [PATCH] improve custom body reader example (#1243) --- lib/plug/parsers.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/plug/parsers.ex b/lib/plug/parsers.ex index a5efb3cf..baf48441 100644 --- a/lib/plug/parsers.ex +++ b/lib/plug/parsers.ex @@ -192,9 +192,10 @@ defmodule Plug.Parsers do defmodule CacheBodyReader do def read_body(conn, opts) do - {:ok, body, conn} = Plug.Conn.read_body(conn, opts) - conn = update_in(conn.assigns[:raw_body], &[body | (&1 || [])]) - {:ok, body, conn} + with {:ok, body, conn} <- Plug.Conn.read_body(conn, opts) do + conn = update_in(conn.assigns[:raw_body], &[body | &1 || []]) + {:ok, body, conn} + end end end