Skip to content

Commit 5fcefe4

Browse files
committed
Upgrade to twilight 0.17
- **Major change** The pretty metric route names are replaced with raw paths - Non-standard global rate limits are unsupported
1 parent bc6419b commit 5fcefe4

File tree

6 files changed

+121
-225
lines changed

6 files changed

+121
-225
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tokio = { version = "1.43", features = ["rt-multi-thread", "macros", "signal"] }
1616
tokio-util = { version = "0.7.8", default-features = false, features = ["time"] }
1717
tracing = "0.1"
1818
tracing-subscriber = "0.3"
19-
twilight-http-ratelimiting = { version = "0.16.0" }
19+
twilight-http-ratelimiting = { git = "https://github.com/twilight-rs/twilight.git", branch = "next" }
2020

2121
metrics = { version = "0.24", optional = true }
2222
metrics-exporter-prometheus = { version = "0.17", default-features = false, optional = true }

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ If processing an incoming request fails, the proxy will respond with a 5xx
130130
status code and a helpful error message in the response body. Currently, these
131131
status codes include:
132132

133-
- `500` if the proxy generates an invalid URI or the ratelimiter fails
134-
internally
135-
- `501` if the client requested an unsupported API path or used an unsupported
136-
HTTP method
133+
- `500` if the proxy encountered an internal error
134+
- `501` if the client requested an unsupported API endpoint
137135
- `502` if the request made by the proxy fails
138136

139137
[twilight]: https://github.com/twilight-rs/twilight

src/error.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
1-
use http::{Method, Response, uri::InvalidUri};
1+
use http::{Method, Response};
22
use http_body_util::{BodyExt, Full, combinators::BoxBody};
33
use hyper::body::Bytes;
44
use hyper_util::client::legacy::Error as HyperUtilError;
55
use std::{
66
error::Error,
77
fmt::{Display, Formatter, Result as FmtResult},
88
};
9-
use twilight_http_ratelimiting::request::PathParseError;
109

11-
static ACQUIRING_TICKET_FAILED_MSG: &str =
12-
"http-proxy: Acquiring ticket from the ratelimiter failed";
13-
static INVALID_URI_MSG: &str = "http-proxy: Failed to create URI for requesting Discord API";
1410
static INVALID_METHOD_MSG: &str = "http-proxy: Unsupported HTTP method in request";
15-
static INVALID_PATH_MSG: &str = "http-proxy: Failed to parse API path from client request";
1611
static REQUEST_ISSUE_MSG: &str = "http-proxy: Error requesting the Discord API";
1712

1813
#[allow(clippy::module_name_repetitions)]
1914
#[derive(Debug)]
2015
pub enum RequestError {
21-
AcquiringTicket {
22-
source: Box<dyn Error + Send + Sync>,
23-
},
24-
InvalidMethod {
25-
method: Method,
26-
},
27-
InvalidPath {
28-
source: PathParseError,
29-
},
30-
InvalidURI {
31-
source: InvalidUri,
32-
},
33-
RequestIssue {
34-
source: HyperUtilError,
35-
},
16+
InvalidMethod { method: Method },
17+
RequestIssue { source: HyperUtilError },
3618
}
3719

3820
impl RequestError {
3921
pub fn as_response(&self) -> Response<BoxBody<Bytes, hyper::Error>> {
4022
let (status_code, body_incoming) = match self {
41-
RequestError::AcquiringTicket { .. } => (500, ACQUIRING_TICKET_FAILED_MSG),
42-
RequestError::InvalidURI { .. } => (500, INVALID_URI_MSG),
4323
RequestError::InvalidMethod { .. } => (501, INVALID_METHOD_MSG),
44-
RequestError::InvalidPath { .. } => (501, INVALID_PATH_MSG),
4524
RequestError::RequestIssue { .. } => (502, REQUEST_ISSUE_MSG),
4625
};
4726

@@ -57,22 +36,10 @@ impl RequestError {
5736
impl Display for RequestError {
5837
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
5938
match self {
60-
Self::AcquiringTicket { source } => {
61-
f.write_str("error when acquiring ratelimiting ticket: ")?;
62-
source.fmt(f)
63-
}
6439
Self::InvalidMethod { method } => {
6540
f.write_str("invalid method: ")?;
6641
method.fmt(f)
6742
}
68-
Self::InvalidPath { source } => {
69-
f.write_str("invalid path: ")?;
70-
source.fmt(f)
71-
}
72-
Self::InvalidURI { source } => {
73-
f.write_str("generated uri for discord api is invalid: ")?;
74-
source.fmt(f)
75-
}
7643
Self::RequestIssue { source } => {
7744
f.write_str("error executing request: ")?;
7845
source.fmt(f)

0 commit comments

Comments
 (0)