From 83c52a3c232b4ecd33855cb067a91814ba2b8ce4 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Mon, 14 Oct 2024 01:26:02 -0500 Subject: [PATCH] Server Timeouts for commands --- src/api/command.rs | 5 +++++ src/api/error.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/command.rs b/src/api/command.rs index 646c24674..64ef42903 100644 --- a/src/api/command.rs +++ b/src/api/command.rs @@ -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; @@ -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)|+)?); diff --git a/src/api/error.rs b/src/api/error.rs index 701217fdd..43c606e2e 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -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