Enum twilight_http::error::ErrorType

source ·
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BuildingRequest

§

ChunkingResponse

§

CreatingHeader

Fields

§name: String
§

Json

§

Parsing

Fields

§body: Vec<u8>
§

RatelimiterTicket

§

RequestCanceled

§

RequestError

§

RequestTimedOut

§

Response

Fields

§body: Vec<u8>
§error: ApiError
§status: StatusCode
§

ServiceUnavailable

API service is unavailable. Consider re-sending the request at a later time.

This may occur during Discord API stability incidents.

Fields

§response: Response<Incoming>
§

Unauthorized

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());

Trait Implementations§

source§

impl Debug for ErrorType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more