Kong.service.request.enable_buffering() enabled but still getting the same error

post-function plugin:

access phase:

body filter phase:

if kong.service and kong.service.response and kong.service.response.get_body() and kong.service.response.get_body().error and kong.service.response.get_body().error.message then kong.response.set_header("statusMsg", kong.service.response.get_body().error.message) end 

kong logs:

2022/10/18 05:00:42 [error] 1098#0: 25204151 failed to run body_filter_by_lua: /usr/local/share/lua/5.1/kong/tools/kong-lua-sandbox.lua:164: [string “if kong.service and kong.service.response and…”]:1: service body is only available with buffered proxying (see: kong.service.request.enable_buffering function)

This error is coming when I don’t pass any authorization key in the requst header , and auth-key plugin is enabled. Throws 504 bad gateway. Other than that it seems to work fine.