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

231
Views
¿Cuándo vería un "error" anidado en este archivo interceptor de errores angular?

Estoy siguiendo un par de tutoriales de Udemy en línea link1 link2 que crean un archivo de interceptor de errores Angular en el lado del cliente. Estoy tratando de entender cómo y cuándo vería una declaración dentro de este archivo que se ve así con un error anidado.

 if (error.status === 400) { if (error.error.errors) { // not sure why we would have a nested error inside error throw error.error; } else { this.alertService.danger(error.error.message); } }

Aquí está el archivo completo

 @Injectable() export class ErrorInterceptor implements HttpInterceptor { constructor(private router: Router, private alertService: AlertService) {} intercept(req: HttpRequest < any > , next: HttpHandler): Observable < HttpEvent < any >> { return next.handle(req).pipe( catchError(error => { if (error) { if (error.status === 400) { if (error.error.errors) { // not sure why we would have a nested error? throw error.error; } else { this.alertService.danger(error.error.message); } } if (error.status === 401) { this.alertService.danger(error.error.message); } if (error.status === 404) { this.router.navigateByUrl('/not-found'); } if (error.status === 500) { const navigationExtras: NavigationExtras = { state: { error: error.error } }; this.router.navigateByUrl('/server-error', navigationExtras); } } return throwError(error); }) ); } }

En el extremo del servidor .Net, tengo controladores que devuelven declaraciones en su mayoría como esta:

 return NotFound("Some message"); return BadRequest("Some message"); return Unauthorized("Some message"); return Ok();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Revisé el código de la API, así que cuando la API devuelva esta respuesta (como contenido del cuerpo)

 { errors: [], message: "" }

pero no (que mi comentario fue incorrecto) :

 { error: { errors: [], message: "" } }

para casos de error/excepción. Entonces, el error adicional no proviene de la respuesta de la API.

Referencia: ExceptionMiddleware


Creo que el error es HttpErrorResponse . Y tiene el atributo de error .

 class HttpErrorResponse extends HttpResponseBase implements Error { constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }) name: 'HttpErrorResponse' message: string error: any | null ok: false // inherited from common/http/HttpResponseBase constructor(init: { headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }, defaultStatus: number = 200, defaultStatusText: string = 'OK') headers: HttpHeaders status: number statusText: string url: string | null ok: boolean type: HttpEventType.Response | HttpEventType.ResponseHeader }

Por lo tanto, para obtener el cuerpo del error , necesita:

 error.error
about 4 years ago · Juan Pablo Isaza Report
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!