Skip to content

Commit

Permalink
Server Timeouts for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Oct 14, 2024
1 parent ab2ec93 commit 83c52a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/api/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub trait Command: sealed::Sealed {
/// on the request.
const RATE_LIMIT: RateLimit;

/// On the server side, how long to wait before timing out the request.
const SERVER_TIMEOUT: Duration;

/// Path pattern for the command (without query) when used with matchit 0.8 or higher.
const ROUTE_PATTERN: &'static str;

Expand Down Expand Up @@ -375,6 +378,8 @@ macro_rules! command {
..RateLimit::DEFAULT
};

const SERVER_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5);

#[allow(unused_mut, unused_variables, deprecated)]
fn perms(&self) -> Permissions {
let mut base = crate::perms!($($($perm)|+)?);
Expand Down
4 changes: 3 additions & 1 deletion src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ error_codes! {
40034 = Blocked = StatusCode::FORBIDDEN,
40035 = Banned = StatusCode::FORBIDDEN,
40036 = SearchError = StatusCode::BAD_REQUEST,
40047 = IncorrectRpcEndpoint = StatusCode::BAD_REQUEST,

// Generic HTTP-like error codes
40400 = BadRequest = StatusCode::BAD_REQUEST,
40401 = Unauthorized = StatusCode::UNAUTHORIZED,
40404 = NotFound = StatusCode::NOT_FOUND,
40405 = MethodNotAllowed = StatusCode::METHOD_NOT_ALLOWED,
40408 = RequestTimeout = StatusCode::REQUEST_TIMEOUT,
40409 = Conflict = StatusCode::CONFLICT,
40413 = RequestEntityTooLarge = unsafe { StatusCode::from_u16(413).unwrap_unchecked() }, // 413 Request Entity Too Large
40413 = RequestEntityTooLarge = StatusCode::PAYLOAD_TOO_LARGE, // 413 Request Entity Too Large
40415 = UnsupportedMediaType = StatusCode::UNSUPPORTED_MEDIA_TYPE,
40460 = ChecksumMismatch = unsafe { StatusCode::from_u16(460).unwrap_unchecked() }, // 460 Checksum Mismatch

Expand Down

0 comments on commit 83c52a3

Please sign in to comment.