Skip to content

add methods for mapping error responses#2979

Open
robjtede wants to merge 2 commits into
mainfrom
error-response-mapping
Open

add methods for mapping error responses#2979
robjtede wants to merge 2 commits into
mainfrom
error-response-mapping

Conversation

@robjtede

@robjtede robjtede commented Feb 13, 2023

Copy link
Copy Markdown
Member

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

Give ability for users, middleware in particular, to alter the response generated from Errors.

@robjtede robjtede added B-semver-minor A-web project: actix-web labels Feb 13, 2023
@robjtede robjtede added this to the actix-web v4.4 milestone Feb 13, 2023
@robjtede robjtede modified the milestones: actix-web v4.4, actix-web v4.5 Aug 29, 2023
@robjtede robjtede removed this from the actix-web v4.5 milestone Feb 4, 2024

@Samielakkad Samielakkad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of response mappers is interesting, but the public API as written has an extra generic type parameter that callers cannot infer:

pub fn add_mapper<F, B>(&mut self, mapper: F)
where
    F: Fn(HttpResponse) -> HttpResponse + 'static,

B is not used in the argument list, return type, or bounds, so a normal call like:

err.add_mapper(|res| res)

will require the caller to specify a meaningless generic parameter or fail type inference. This should probably just be pub fn add_mapper<F>(...) unless B was intended to be part of the mapper signature.

It would also be good to add a small compile/pass test or unit test that actually calls add_mapper through the public API, so this kind of inference issue is caught.

@robjtede
robjtede force-pushed the error-response-mapping branch from eb10b74 to 473956a Compare July 17, 2026 11:03
@robjtede
robjtede force-pushed the error-response-mapping branch from 473956a to 7b79694 Compare July 17, 2026 12:00
@robjtede
robjtede requested a review from JohnTitor July 17, 2026 12:02
@robjtede
robjtede marked this pull request as ready for review July 17, 2026 12:02
@robjtede

Copy link
Copy Markdown
Member Author

@JohnTitor basically an attempt to work around actix/actix-extras#680 in a nonbreaking way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-web project: actix-web B-semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants