Retrieving the response code or body to use as a condition to send another request within tryMax

I have this request that is querying my service which is inside of tryMax. The access token to authenticate a request expires every five minutes and is generated at the beginning of the simulation run as ${token} Is there a way within the tryMax to send another token generation request that will update the expired ${token} (Authorization header value) if the response code is 401 or the response body contains information about the request not being authenticated. Then retry the request before tryMax moves to the next iteration? I have tried setting status code as a session attribute, however the request is not being sent and the token doesn’t update, I tried doing a .doIf after the request exec, putting a doIf inside it’s own exec and even playing around with transformResponse, all with no success. Any suggestions how to approach this?