(state: &Rc<RefCell<OpState>>, code: u16)
| 325 | } |
| 326 | |
| 327 | fn check_bad_request(state: &Rc<RefCell<OpState>>, code: u16) -> Result<(), ()> { |
| 328 | if code == 401 || code == 403 || code == 429 { |
| 329 | let mut rc = state.borrow_mut(); |
| 330 | let dstate = rc.borrow_mut::<DiscordOpsState>(); |
| 331 | dstate.add_failed_req(); |
| 332 | if dstate.should_suspend_guild() { |
| 333 | let handle = rc.borrow::<vm::vm::VmShutdownHandle>().clone(); |
| 334 | let rt_ctx = rc.borrow::<RuntimeContext>().clone(); |
| 335 | drop(rc); |
| 336 | |
| 337 | warn!( |
| 338 | guild_id = rt_ctx.guild_id.get(), |
| 339 | "guild hit >30 invalid requests within 60s, suspending it" |
| 340 | ); |
| 341 | handle.shutdown_vm( |
| 342 | vm::vm::ShutdownReason::DiscordInvalidRequestsRatelimit, |
| 343 | false, |
| 344 | ); |
| 345 | |
| 346 | return Err(()); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | Ok(()) |
| 351 | } |
| 352 | |
| 353 | pub fn handle_discord_error(state: &Rc<RefCell<OpState>>, err: twilight_http::Error) -> AnyError { |
| 354 | let kind = err.kind(); |
no test coverage detected