Compare commits

...

5 Commits

Author SHA1 Message Date
Rob Ede 17b4ae3ed4
Merge eb10b74751 into 3f9d88f859 2025-07-09 00:31:29 +02:00
dependabot[bot] 3f9d88f859
build(deps): bump taiki-e/install-action from 2.54.0 to 2.54.3 (#3686)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.54.0 to 2.54.3.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/install-action/compare/v2.54.0...v2.54.3)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.54.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:59:38 +00:00
dependabot[bot] 2eb801cb59
build(deps): bump taiki-e/cache-cargo-install-action from 2.1.2 to 2.2.0 (#3687)
Bumps [taiki-e/cache-cargo-install-action](https://github.com/taiki-e/cache-cargo-install-action) from 2.1.2 to 2.2.0.
- [Release notes](https://github.com/taiki-e/cache-cargo-install-action/releases)
- [Changelog](https://github.com/taiki-e/cache-cargo-install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/cache-cargo-install-action/compare/v2.1.2...v2.2.0)

---
updated-dependencies:
- dependency-name: taiki-e/cache-cargo-install-action
  dependency-version: 2.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:58:36 +00:00
Rob Ede eb10b74751
Merge branch 'master' into error-response-mapping 2024-06-10 01:31:51 +01:00
Rob Ede 98c99f3bc2
add methods for mapping error responses 2023-02-13 23:40:23 +00:00
5 changed files with 24 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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(),
} }
} }
} }