#[non_exhaustive]pub struct ApiError {
pub code: ErrorCode,
pub message: String,
pub field_errors: Vec<FieldError>,
pub errors: Option<Value>,
}Expand description
The JSON error body Discord returns with 4xx responses.
Its Display shows the message and code, then one line per
field error, e.g.:
Invalid Form Body (code 50035)
embeds[0].title[BASE_TYPE_REQUIRED]: This field is requiredSee error messages and JSON error codes.
discord.js counterpart: DiscordAPIError.
§Examples
use djs_model::rest::ErrorCode;
use djs_rest::ApiError;
let error: ApiError = serde_json::from_str(
r#"{"code": 50035, "message": "Invalid Form Body", "errors": {
"content": {"_errors": [{"code": "BASE_TYPE_MAX_LENGTH",
"message": "Must be 2000 or fewer in length."}]}}}"#,
)
.unwrap();
assert_eq!(error.code, ErrorCode::InvalidFormBodyOrContentType);
assert_eq!(error.field_errors[0].path, "content");
assert_eq!(
error.to_string(),
"Invalid Form Body (code 50035)\ncontent[BASE_TYPE_MAX_LENGTH]: Must be 2000 or fewer in length."
);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: ErrorCodeThe JSON error code,
e.g. MissingPermissions (D-097).
message: StringA human-readable description of the error.
field_errors: Vec<FieldError>The detailed errors of the request’s fields (mostly with
InvalidFormBodyOrContentType), flattened
from errors (D-099). Empty if Discord sent none.
errors: Option<Value>The nested errors object as Discord sent it.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ApiError
impl<'de> Deserialize<'de> for ApiError
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for ApiError
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl UnwindSafe for ApiError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of [
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a [
CompactString]. Read more