diff --git a/backend/src/main.rs b/backend/src/main.rs index e3334f6..d231e34 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -159,14 +159,14 @@ async fn main() -> io::Result<()> { let governor_config = GovernorConfigBuilder::default() .key_extractor(NginxIpKeyExctrator) .per_second(10) - .burst_size(5) + .burst_size(20) .use_headers() .finish() .unwrap(); #[cfg(not(feature = "proxy"))] let governor_config = GovernorConfigBuilder::default() .per_second(10) - .burst_size(5) + .burst_size(20) .use_headers() .finish() .unwrap(); diff --git a/frontend/src/api/frontmatter.ts b/frontend/src/api/frontmatter.ts index a2df424..67cba8b 100644 --- a/frontend/src/api/frontmatter.ts +++ b/frontend/src/api/frontmatter.ts @@ -14,6 +14,9 @@ class Request { if (!result.body) { return Promise.reject({ status: 500, message: "Server Connection Failed" }); } + if (result.status == 429) { + return Promise.reject(new Error("Too many requests. Try again later")); + } let stream = await Request.readStream(result.body); let body = JSON.parse(stream); if (!body.success) { @@ -31,6 +34,9 @@ class Request { method: "GET", credentials: "include" }); + if (result.status == 429) { + return Promise.reject(new Error("Too many requests. Try again later")); + } const body = await result.json(); if (!body.success) { return Promise.reject(body.body); diff --git a/frontend/src/api/main.ts b/frontend/src/api/main.ts index c9eb018..d3615d1 100644 --- a/frontend/src/api/main.ts +++ b/frontend/src/api/main.ts @@ -90,4 +90,4 @@ async function readStream(stream: ReadableStream) { chunks.push(textDecode.decode(value)); } return chunks.join(""); -} \ No newline at end of file +} diff --git a/frontend/src/api/theBackend.ts b/frontend/src/api/theBackend.ts index 8a17773..9b8bd60 100644 --- a/frontend/src/api/theBackend.ts +++ b/frontend/src/api/theBackend.ts @@ -17,6 +17,9 @@ class Request { if (!result.body) { return Promise.reject({ status: 500, message: "Server Connection Failed" }); } + if (result.status == 429) { + return Promise.reject(new Error("Too many requests. Try again later")); + } let stream = await Request.readStream(result.body); let body = JSON.parse(stream); if (!body.success) { @@ -34,6 +37,9 @@ class Request { method: "GET", credentials: "include" }); + if (result.status == 429) { + return Promise.reject(new Error("Too many requests. Try again later")); + } const body = await result.json(); if (!body.success) { return Promise.reject(body.body);