Skip to content

feat: add take_error to responses and expand HttpResponse conversions#4041

Open
iamfaiz123 wants to merge 2 commits intoactix:mainfrom
iamfaiz123:feat/http-response-take-error
Open

feat: add take_error to responses and expand HttpResponse conversions#4041
iamfaiz123 wants to merge 2 commits intoactix:mainfrom
iamfaiz123:feat/http-response-take-error

Conversation

@iamfaiz123
Copy link
Copy Markdown

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

This PR enhances the HttpResponse and ServiceResponse APIs by adding a take_error() method and expanding available type conversions.

Changes:

  • take_error() Method: Added to both HttpResponse and ServiceResponse. This allows callers (particularly middleware) to take ownership of the inner Error, leaving None in its place.
  • Expanded HttpResponse Conversions: Added From implementations for HttpResponse from common types including String, &String, Vec<u8>, &Vec<u8>, Bytes, and ByteString.
  • ServiceRequest::into_response Flexibility: Updated to accept Into<HttpResponse<B>> instead of Into<Response<B>>, providing better ergonomics when converting requests to responses.
  • Testing: Added unit tests in response.rs and service.rs to verify that take_error() correctly extracts the error and leaves the response state consistent.

Issues:

Breaking Changes:

  • The signature change of ServiceRequest::into_response from Into<Response<B>> to Into<HttpResponse<B>> is a minor breaking change for any custom types implementing Into<Response<B>> but not Into<HttpResponse<B>>.

@github-actions github-actions Bot added the A-web project: actix-web label Apr 22, 2026
@robjtede robjtede added the B-semver-major breaking change requiring a major version bump label Apr 22, 2026
@robjtede robjtede added this to the actix-web v5.0 milestone Apr 22, 2026
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-major breaking change requiring a major version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to get ownership of error of response

2 participants