Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda