Skip to content

Commit

Permalink
fix: Add better warning for rate limit (fix #67) and increase burst t…
Browse files Browse the repository at this point in the history
…o 20
ixhbinphoenix committed Mar 20, 2024
1 parent d186481 commit 09bab9a
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
6 changes: 6 additions & 0 deletions frontend/src/api/frontmatter.ts
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion frontend/src/api/main.ts
Original file line number Diff line number Diff line change
@@ -84,4 +84,4 @@ async function readStream(stream: ReadableStream<Uint8Array>) {
chunks.push(textDecode.decode(value));
}
return chunks.join("");
}
}
6 changes: 6 additions & 0 deletions frontend/src/api/theBackend.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 09bab9a

Please sign in to comment.