MCPcopy Create free account
hub / github.com/Botloader/botloader / error_from_code

Function error_from_code

components/runtime/src/extensions/discord.rs:374–414  ·  view source on GitHub ↗
(
    resp_code: StatusCode,
    code: u64,
    message: &str,
    body: &Vec<u8>,
)

Source from the content-addressed store, hash-verified

372}
373
374pub fn error_from_code(
375 resp_code: StatusCode,
376 code: u64,
377 message: &str,
378 body: &Vec<u8>,
379) -> AnyError {
380 match resp_code.get() {
381 404 => not_found_error(format!("{code}: {message}")),
382 403 => custom_error("DiscordPermissionsError", format!("{code}: {message}")),
383 400..=499 => match code {
384 30001..=40000 => custom_error("DiscordLimitReachedError", format!("{code}: {message}")),
385 50035 => {
386 if let Ok(parsed) = serde_json::from_slice::<BlDiscordApiError>(&body) {
387 if let Some(errors) = parsed.errors {
388 return custom_error(
389 "DiscordFormError",
390 format!("{code}: {message} - {}", errors),
391 );
392 }
393 }
394
395 custom_error("DiscordGenericErrorResponse", format!("{code}: {message}"))
396 }
397 _ => custom_error("DiscordGenericErrorResponse", format!("{code}: {message}")),
398 },
399 status @ 500..=599 => custom_error(
400 "DiscordServerErrorResponse",
401 format!(
402 "Discord failed handling the request (5xx response), http status: {status}, code: \
403 {code}, message: {message}"
404 ),
405 ),
406 other => custom_error(
407 "DiscordGenericErrorResponse",
408 format!(
409 "An error occurred with the discord API, http status: {other}, code: {code}, \
410 message: {message}"
411 ),
412 ),
413 }
414}
415
416const DISCORD_NOT_FOUND_CLASS_NAME: &str = "DiscordNotFoundError";
417

Callers 1

handle_discord_errorFunction · 0.85

Calls 2

not_found_errorFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected