(state: &Rc<RefCell<OpState>>, err: twilight_http::Error)
| 351 | } |
| 352 | |
| 353 | pub fn handle_discord_error(state: &Rc<RefCell<OpState>>, err: twilight_http::Error) -> AnyError { |
| 354 | let kind = err.kind(); |
| 355 | if let ErrorType::Response { status, .. } = kind { |
| 356 | // check if this guild has run into a lot of "invalid" requests |
| 357 | // |
| 358 | // this is needed because discord will ban our IP if we exceed 10_000 invalid req/10min as of writing |
| 359 | let raw = status.get(); |
| 360 | let _ = check_bad_request(state, raw); |
| 361 | } |
| 362 | |
| 363 | match kind { |
| 364 | ErrorType::Response { |
| 365 | // 10008 is unknown message |
| 366 | error: ApiError::General(GeneralApiError { code, message, .. }), |
| 367 | status, |
| 368 | body, |
| 369 | } => error_from_code(*status, *code, message, body), |
| 370 | _ => err.into(), |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | pub fn error_from_code( |
| 375 | resp_code: StatusCode, |
no test coverage detected