1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-02-22 20:13:17 +01:00
John Vandenberg d6bdfac1b9
build(deps): update derive_more to v1.0 (#3453)
* build(deps): update derive_more to v1.0

* refactor: use from derive module

---------

Co-authored-by: Rob Ede <robjtede@icloud.com>
2024-08-18 14:17:03 +00:00

50 lines
1.4 KiB
Rust

use actix_web::{http::StatusCode, ResponseError};
use derive_more::derive::Display;
/// Errors which can occur when serving static files.
#[derive(Debug, PartialEq, Eq, Display)]
pub enum FilesError {
/// Path is not a directory.
#[allow(dead_code)]
#[display("path is not a directory. Unable to serve static files")]
IsNotDirectory,
/// Cannot render directory.
#[display("unable to render directory without index file")]
IsDirectory,
}
impl ResponseError for FilesError {
/// Returns `404 Not Found`.
fn status_code(&self) -> StatusCode {
StatusCode::NOT_FOUND
}
}
#[derive(Debug, PartialEq, Eq, Display)]
#[non_exhaustive]
pub enum UriSegmentError {
/// Segment started with the wrapped invalid character.
#[display("segment started with invalid character: ('{_0}')")]
BadStart(char),
/// Segment contained the wrapped invalid character.
#[display("segment contained invalid character ('{_0}')")]
BadChar(char),
/// Segment ended with the wrapped invalid character.
#[display("segment ended with invalid character: ('{_0}')")]
BadEnd(char),
/// Path is not a valid UTF-8 string after percent-decoding.
#[display("path is not a valid UTF-8 string after percent-decoding")]
NotValidUtf8,
}
impl ResponseError for UriSegmentError {
/// Returns `400 Bad Request`.
fn status_code(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}