mirror of https://github.com/fafhrd91/actix-web
Compare commits
5 Commits
d3a4db2b69
...
17b4ae3ed4
Author | SHA1 | Date |
---|---|---|
|
17b4ae3ed4 | |
|
3f9d88f859 | |
|
2eb801cb59 | |
|
eb10b74751 | |
|
98c99f3bc2 |
|
@ -49,7 +49,7 @@ jobs:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ jobs:
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
|
||||||
|
|
||||||
- name: Install just, cargo-hack
|
- name: Install just, cargo-hack
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack
|
tool: just,cargo-hack
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ jobs:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ jobs:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
|
|
||||||
- name: Install just
|
- name: Install just
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ jobs:
|
||||||
components: llvm-tools
|
components: llvm-tools
|
||||||
|
|
||||||
- name: Install just, cargo-llvm-cov, cargo-nextest
|
- name: Install just, cargo-llvm-cov, cargo-nextest
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-llvm-cov,cargo-nextest
|
tool: just,cargo-llvm-cov,cargo-nextest
|
||||||
|
|
||||||
|
|
|
@ -77,12 +77,12 @@ jobs:
|
||||||
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||||
|
|
||||||
- name: Install just
|
- name: Install just
|
||||||
uses: taiki-e/install-action@v2.54.0
|
uses: taiki-e/install-action@v2.54.3
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
- name: Install cargo-check-external-types
|
- name: Install cargo-check-external-types
|
||||||
uses: taiki-e/cache-cargo-install-action@v2.1.2
|
uses: taiki-e/cache-cargo-install-action@v2.2.0
|
||||||
with:
|
with:
|
||||||
tool: cargo-check-external-types
|
tool: cargo-check-external-types
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{HttpResponse, ResponseError};
|
||||||
|
|
||||||
/// General purpose Actix Web error.
|
/// General purpose Actix Web error.
|
||||||
///
|
///
|
||||||
/// An Actix Web error is used to carry errors from `std::error` through actix in a convenient way.
|
/// An Actix Web error is used to carry errors from `std::error` through Actix in a convenient way.
|
||||||
/// It can be created through converting errors with `into()`.
|
/// It can be created through converting errors with `into()`.
|
||||||
///
|
///
|
||||||
/// Whenever it is created from an external object a response error is created for it that can be
|
/// Whenever it is created from an external object a response error is created for it that can be
|
||||||
|
@ -14,6 +14,7 @@ use crate::{HttpResponse, ResponseError};
|
||||||
/// you can always get a `ResponseError` reference from it.
|
/// you can always get a `ResponseError` reference from it.
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
cause: Box<dyn ResponseError>,
|
cause: Box<dyn ResponseError>,
|
||||||
|
response_mappers: Vec<Box<dyn Fn(HttpResponse) -> HttpResponse>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
@ -29,7 +30,20 @@ impl Error {
|
||||||
|
|
||||||
/// Shortcut for creating an `HttpResponse`.
|
/// Shortcut for creating an `HttpResponse`.
|
||||||
pub fn error_response(&self) -> HttpResponse {
|
pub fn error_response(&self) -> HttpResponse {
|
||||||
self.cause.error_response()
|
let mut res = self.cause.error_response();
|
||||||
|
|
||||||
|
for mapper in &self.response_mappers {
|
||||||
|
res = (mapper)(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_mapper<F, B>(&mut self, mapper: F)
|
||||||
|
where
|
||||||
|
F: Fn(HttpResponse) -> HttpResponse + 'static,
|
||||||
|
{
|
||||||
|
self.response_mappers.push(Box::new(mapper))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +70,7 @@ impl<T: ResponseError + 'static> From<T> for Error {
|
||||||
fn from(err: T) -> Error {
|
fn from(err: T) -> Error {
|
||||||
Error {
|
Error {
|
||||||
cause: Box::new(err),
|
cause: Box::new(err),
|
||||||
|
response_mappers: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue