Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:36:44+00:00 2026-06-09T11:36:44+00:00

While in the ResponseFilters is there anyway to get the status code (and description)

  • 0

While in the ResponseFilters is there anyway to get the status code (and description) which is going back to the client?

Long explanation:
I’m looking into adding a response header while I’m in a response filter. The issue is that in our API we set on some NotFound & BadRequest returns a message for the user in the status description;

return HttpError.NotFound(string.Format("Not found with TicketCodeId {0}",
       request.TicketCodeId))

This works great in android and .net clients of all sorts.
But some clients (I’m looking at you iphone) don’t get the status description. The idea is to see in the responsefilter that the status code is set to 400 range and it has a special message, then add a header and copy the status message description into it.

Problem is ResponseFilter has access to IHttpResponse, and that object has only a setter to the statuscode (so no way for me to determine if I need to add the header).

I want to solve it in this generic way to avoid having to remember (and go back over all service implementations) everywhere a 400 status code is set to add the same description to a header. It would be nice if this is done in a single place, the ResponseFilter.

ResponseFilter documentation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:36:45+00:00Added an answer on June 9, 2026 at 11:36 am

    Since we are returning all responses with BadRequest and NotFound where we use a message in the status description as either an HttpError or HttpResult (which both are of type IHttpResult) I can do the following to create the desired extra header:

    // Add Filter: If result is of type IHttpResult then check if the statuscode 
    // is 400 or higher and the statusdescription is set.
    this.ResponseFilters.Add((req, res, dto) =>
    {
        if (dto == null) return;
    
        var httpResult = dto as IHttpResult;
        if (dto is IHttpResult)
        {
            // If statuscode is 400 then add a Header with the error message; 
            // this since not all clients can read the statusdescription
            if ((int)httpResult.StatusCode >= 400)
                AddPmErrorMessageHeader(res, httpResult.StatusDescription);
        }
    });
    

    The AddPmErrorMessageHeader method will do some extra validation and use the res object to add the header:

    res.AddHeader("PmErrorMessage", statusDescription);
    

    I did some testing with the res.OriginalResponse but that somehow always has the StatusCode set to 200, even when just before setting the 4** status code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While looking at existing code and my own applications, sometimes it's easy to get
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
While refactoring my code base I found a piece of code which I'd like
While executing this below Dojo code the call back mehod is calling the onFailure.
While working in a project written by some one else ,there's a Function which
While trying to compile the following code, which is enhanced version of read build
While declaring a simple UIAlertView, with the following code, I get the above mentionned
While debugging and keep pressing F5, if the source code does not exist, eclipse
while($c=fgets(STDIN)){ if($c===PHP_EOL){ continue; } else { echo $c; } } When the above code
While calling XslCompiledTransform.Transform() method I get this exception : The Writer is closed or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.