You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I noticed that if an error is thrown by my loader function (or any helper function it calls), via throw new Error(), react-router will still send whatever cache-control headers I'm returning in my exported headers function. I know that I can return headers from my loader and access them via loaderHeaders, but I don't want to have to rely on my loader in that way if I can avoid it, because I always want the cache-control headers to be the same for this loader except when there's an error. Also, I want to set some default headers in a reusable way in a few of my loaders, and having to always use loaderHeaders seems brittle.
Is there any solution for this using existing react-router features? I checked out the HeadersArgs passed to the headers function, but at least in my case all of those arguments are exactly the same regardless of whether it's an error response or a 200 response.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I noticed that if an error is thrown by my loader function (or any helper function it calls), via
throw new Error()
, react-router will still send whatevercache-control
headers I'm returning in my exportedheaders
function. I know that I can return headers from my loader and access them vialoaderHeaders
, but I don't want to have to rely on my loader in that way if I can avoid it, because I always want the cache-control headers to be the same for this loader except when there's an error. Also, I want to set some default headers in a reusable way in a few of my loaders, and having to always useloaderHeaders
seems brittle.Is there any solution for this using existing react-router features? I checked out the
HeadersArgs
passed to theheaders
function, but at least in my case all of those arguments are exactly the same regardless of whether it's an error response or a 200 response.Beta Was this translation helpful? Give feedback.
All reactions