Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Retrieving Content from HttpResponseMessage in client

I can't seem to find a way to retrieve error message when I throw HttpResponseException in Server side code.

Here is global exception filter I use to catch unhandled server side exceptions:

public class ExceptionHandlingAttribute : ExceptionFilterAttribute
{
    private static readonly Logger Nlog = LogManager.GetCurrentClassLogger();

    public override void OnException(HttpActionExecutedContext context)
    {
        string message = context.Exception.Message;

        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
        {
            Content = new StringContent(message),
            ReasonPhrase = "Exception"
        });
    }
}

and here is my client side code (angular2):

    getAll(): Observable<T[]> {
    let url_ = `${this.localUrl}`;
    return this.http.request(url_
    ).map((response) => {
        return this.processArrayResponse(response);
    }).catch((response: any, caught: any) => {
        console.log(response)
        return this.handleArrayResponseError(response);
    });
}

    protected handleAnyResponseError(response: any): Observable<any> {
    if (response instanceof Response) {
        try {
            return Observable.of(this.processAnyResponse(response));
        } catch (e) {
            console.log(e)
            return <Observable<any>><any>Observable.throw(e);
        }
    } else
        return <Observable<any>><any>Observable.throw(response);
}

The response I'm getting is this:

Response {_body: ArrayBuffer, status: 500, ok: false, statusText: "Exception", headers: Headers…}
headers:Headers
ok:false
status:500
statusText:"Exception"
type:2
url:"http://localhost:83/api/PreHeatSchedule/getExportFile"
_body:ArrayBuffer
__proto__: Body

I have no idea how to get the Content part from the exception in client.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!