MultipartError

Enum MultipartError 

Source
pub enum MultipartError {
    InvalidBoundary,
    FieldTooLarge {
        field_name: String,
        max_size: usize,
    },
    TooManyFields {
        max_fields: usize,
    },
    RequestTooLarge {
        max_size: usize,
    },
    InvalidField(String),
    Io(Error),
    InvalidUtf8(Utf8Error),
    Parse(String),
}
Expand description

Errors that can occur during multipart form data parsing.

This enum covers all possible error conditions that may arise when processing multipart/form-data requests, from validation issues to resource limit violations.

§Error Categories

§Validation Errors

  • InvalidBoundary: The boundary parameter is malformed
  • InvalidField: A field has invalid format or headers
  • InvalidUtf8: Text field contains invalid UTF-8 sequences

§Size Limit Errors

  • FieldTooLarge: An individual field exceeds the configured size limit
  • TooManyFields: The request contains more fields than allowed
  • RequestTooLarge: The entire request exceeds the size limit

§System Errors

  • Io: File system or network I/O errors
  • Parse: Low-level parsing errors from the multipart library

§Examples

use ignitia::multipart::MultipartError;

match error {
    MultipartError::FieldTooLarge { field_name, max_size } => {
        println!("Field '{}' is too large (max: {} bytes)", field_name, max_size);
    }
    MultipartError::TooManyFields { max_fields } => {
        println!("Too many fields (max: {})", max_fields);
    }
    MultipartError::InvalidBoundary => {
        println!("Invalid multipart boundary");
    }
    _ => {
        println!("Other multipart error: {}", error);
    }
}

Variants§

§

InvalidBoundary

The multipart boundary parameter is invalid or malformed.

This occurs when the Content-Type header contains an invalid boundary parameter, or when the boundary is not properly formatted according to RFC 2046 specifications.

§HTTP Status

This error maps to HTTP 400 Bad Request.

§

FieldTooLarge

A field exceeds the maximum allowed size.

This error is thrown when an individual field’s content exceeds the max_field_size limit configured in MultipartConfig.

§Fields

  • field_name: The name of the field that exceeded the limit
  • max_size: The maximum allowed size in bytes

§HTTP Status

This error maps to HTTP 413 Payload Too Large.

§Examples

use ignitia::multipart::MultipartError;

let error = MultipartError::FieldTooLarge {
    field_name: "upload_file".to_string(),
    max_size: 1024 * 1024, // 1MB
};

Fields

§field_name: String

Name of the field that exceeded the size limit

§max_size: usize

Maximum allowed size in bytes

§

TooManyFields

The request contains too many fields.

This error occurs when the number of fields in the multipart request exceeds the max_fields limit configured in MultipartConfig.

§Fields

  • max_fields: The maximum number of fields allowed

§HTTP Status

This error maps to HTTP 413 Payload Too Large.

Fields

§max_fields: usize

Maximum number of fields allowed

§

RequestTooLarge

The entire request size exceeds the configured limit.

This error is thrown when the total size of all fields combined exceeds the max_request_size limit configured in MultipartConfig.

§Fields

  • max_size: The maximum allowed request size in bytes

§HTTP Status

This error maps to HTTP 413 Payload Too Large.

Fields

§max_size: usize

Maximum allowed request size in bytes

§

InvalidField(String)

A field has invalid format or headers.

This error occurs when a multipart field is malformed, has missing required headers, or contains invalid header values.

§HTTP Status

This error maps to HTTP 400 Bad Request.

§

Io(Error)

An I/O error occurred during parsing.

This wraps standard I/O errors that may occur when reading from the request stream, writing temporary files, or performing other file system operations.

§HTTP Status

This error maps to HTTP 400 Bad Request (though it could indicate a server-side issue in some cases).

§

InvalidUtf8(Utf8Error)

A text field contains invalid UTF-8 sequences.

This error occurs when attempting to parse a field as text, but the field content is not valid UTF-8.

§HTTP Status

This error maps to HTTP 400 Bad Request.

§

Parse(String)

A low-level parsing error occurred.

This wraps errors from the underlying multipart parsing library, typically indicating malformed multipart data that doesn’t conform to RFC standards.

§HTTP Status

This error maps to HTTP 400 Bad Request.

Trait Implementations§

Source§

impl CustomError for MultipartError

Source§

fn status_code(&self) -> StatusCode

Returns the appropriate HTTP status code for this error.

Size-related errors return 413 Payload Too Large, while validation and parsing errors return 400 Bad Request.

Source§

fn error_type(&self) -> &'static str

Returns a string identifier for the error type.

This is used in structured error responses to help clients programmatically identify and handle different error types.

Source§

fn metadata(&self) -> Option<Value>

Returns additional metadata for structured error responses.

For size-related errors, this includes the limits that were exceeded.

Source§

fn error_code(&self) -> Option<String>

Returns an optional application-specific error code. Read more
Source§

impl Debug for MultipartError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for MultipartError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Error for MultipartError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for MultipartError

Source§

fn from(err: Error) -> Self

Converts standard I/O errors into MultipartError::Io.

This provides automatic conversion for file system and network errors that may occur during multipart processing.

Source§

impl From<MultipartError> for Error

Source§

fn from(err: MultipartError) -> Self

Converts a MultipartError into the framework’s main Error type.

This allows multipart errors to be seamlessly integrated with Ignitia’s error handling and response generation system.

Source§

impl From<MultipartError> for MultipartRejection

Source§

fn from(err: MultipartError) -> Self

Converts a MultipartError into a MultipartRejection.

Source§

impl From<Utf8Error> for MultipartError

Source§

fn from(err: Utf8Error) -> Self

Converts UTF-8 validation errors into MultipartError::InvalidUtf8.

This provides automatic conversion when attempting to parse binary field data as UTF-8 text.

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.

Source§

impl<T> Instrument for T

Source§

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

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

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,