#[non_exhaustive]pub enum ErrorType {
Show 13 variants
    BuildingRequest,
    ChunkingResponse,
    CreatingHeader {
        name: String,
    },
    Json,
    Parsing {
        body: Vec<u8>,
    },
    RatelimiterTicket,
    RequestCanceled,
    RequestError,
    RequestTimedOut,
    Response {
        body: Vec<u8>,
        error: ApiError,
        status: StatusCode,
    },
    ServiceUnavailable {
        response: Response<Incoming>,
    },
    Unauthorized,
    Validation,
}Expand description
Type of Error that occurred.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
BuildingRequest
ChunkingResponse
CreatingHeader
Json
Parsing
RatelimiterTicket
RequestCanceled
RequestError
RequestTimedOut
Response
API service is unavailable. Consider re-sending the request at a later time.
This may occur during Discord API stability incidents.
Token in use has become revoked or is otherwise invalid.
This can occur if a bot token is invalidated or an access token expires or is revoked. Recreate the client to configure a new token.
Validation
A field failed validation requirements during request building.
The inputs of request methods for fields are validated for correctness.
For example, CreateMessage::content is validated to ensure that the
message content isn’t too long; ExecuteWebhook::embeds is validated
to ensure that a correct number of embeds are provided; and so on.
Validation failures aren’t immediately returned; rather, validation
errors are returned when calling the IntoFuture or
TryIntoRequest implementations on requests.
§Examples
Passing a message with valid content succeeds as expected:
use std::env;
use twilight_http::{client::Client, request::TryIntoRequest};
let client = Client::new(env::var("DISCORD_TOKEN")?);
let builder = client.create_message(channel_id).content("Ping!");
assert!(builder.try_into_request().is_ok());However, passing an invalid content returns a validation error upon finalizing the request building:
use std::{env, error::Error};
use twilight_http::{client::Client, error::ErrorType, request::TryIntoRequest};
let client = Client::new(env::var("DISCORD_TOKEN")?);
// this is a very long message
let content = "pinkie pie is cool ".repeat(1000);
let builder = client.create_message(channel_id).content(&content);
let error = builder.try_into_request().unwrap_err();
assert!(matches!(error.kind(), ErrorType::Validation));
// print the contents of the validation error
println!("{:?}", error.source());