feat: rate limit error chaching (#2448)

* feat: rate limit error chaching

Rate limit error caching to alleviate PATs.

* refactor: improve code comments
This commit is contained in:
Rick Staa
2023-09-17 15:45:17 +02:00
committed by GitHub
parent 64f56e88b4
commit bc8eaecaf4
9 changed files with 54 additions and 18 deletions
+6 -1
View File
@@ -77,7 +77,12 @@ export default async (req, res) => {
}),
);
} catch (err) {
res.setHeader("Cache-Control", `no-cache, no-store, must-revalidate`); // Don't cache error responses.
res.setHeader(
"Cache-Control",
`max-age=${CONSTANTS.ERROR_CACHE_SECONDS / 2}, s-maxage=${
CONSTANTS.ERROR_CACHE_SECONDS
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
return res.send(renderError(err.message, err.secondaryMessage));
}
};