mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-27 17:22:57 +01:00
48646d1bd3
* build(deps): update derive_more to v1.0 * chore: remove overspecified deps * chore: use from the derive module * chore: restore unrelated version reqs --------- Co-authored-by: Rob Ede <robjtede@icloud.com>
50 lines
1.8 KiB
Rust
50 lines
1.8 KiB
Rust
use actix_web::{http::StatusCode, HttpResponse, ResponseError};
|
|
use derive_more::derive::{Display, Error};
|
|
|
|
/// Errors that can occur when processing CORS guarded requests.
|
|
#[derive(Debug, Clone, Display, Error)]
|
|
#[non_exhaustive]
|
|
pub enum CorsError {
|
|
/// Allowed origin argument must not be wildcard (`*`).
|
|
#[display("`allowed_origin` argument must not be wildcard (`*`)")]
|
|
WildcardOrigin,
|
|
|
|
/// Request header `Origin` is required but was not provided.
|
|
#[display("Request header `Origin` is required but was not provided")]
|
|
MissingOrigin,
|
|
|
|
/// Request header `Access-Control-Request-Method` is required but is missing.
|
|
#[display("Request header `Access-Control-Request-Method` is required but is missing")]
|
|
MissingRequestMethod,
|
|
|
|
/// Request header `Access-Control-Request-Method` has an invalid value.
|
|
#[display("Request header `Access-Control-Request-Method` has an invalid value")]
|
|
BadRequestMethod,
|
|
|
|
/// Request header `Access-Control-Request-Headers` has an invalid value.
|
|
#[display("Request header `Access-Control-Request-Headers` has an invalid value")]
|
|
BadRequestHeaders,
|
|
|
|
/// Origin is not allowed to make this request.
|
|
#[display("Origin is not allowed to make this request")]
|
|
OriginNotAllowed,
|
|
|
|
/// Request method is not allowed.
|
|
#[display("Requested method is not allowed")]
|
|
MethodNotAllowed,
|
|
|
|
/// One or more request headers are not allowed.
|
|
#[display("One or more request headers are not allowed")]
|
|
HeadersNotAllowed,
|
|
}
|
|
|
|
impl ResponseError for CorsError {
|
|
fn status_code(&self) -> StatusCode {
|
|
StatusCode::BAD_REQUEST
|
|
}
|
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
HttpResponse::with_body(self.status_code(), self.to_string()).map_into_boxed_body()
|
|
}
|
|
}
|