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

225
Views
Recuperando contenido de HttpResponseMessage en el cliente

Parece que no puedo encontrar una manera de recuperar el mensaje de error cuando lanzo HttpResponseException en el código del lado del servidor.

Aquí está el filtro de excepción global que uso para detectar excepciones del lado del servidor no controladas:

 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" }); } }

y aquí está mi código del lado del cliente (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); }

La respuesta que recibo es esta:

 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

No tengo idea de cómo obtener la parte de Contenido de la excepción en el cliente.

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!