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

326
Views
No capturado (en promesa): Respuesta con estado: 401 No autorizado para URL

ingrese la descripción de la imagen aquíEstoy tratando de implementar authGuard para mis enrutadores. pero cuando interfiero con los códigos de error, la aplicación se rompe. No sé cómo abordarlo. asistencia necesaria.

Mi AuthGuard

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { return this._auth.validate() .map((isValidated) => { if (isValidated && localStorage.getItem('authToken') && this.checkCookie()) { return true; } this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } }); return false; }); }

Mi servicio de autenticación

 @Injectable() export class AuthService { loginStatus; constructor(private http: Http, private _apiEndPoint: ApiEndPoint, private router: Router) { } validate() { return this.http.get(this._apiEndPoint.validate) .map( (response: Response) => { const result = response.json(); // check authentication status from response if (result.authenticated) { return true; } else { return false; } }) .catch(error => Observable.throw(error)); } }

Recibo este error, No capturado (en promesa): Respuesta con estado: 401 No autorizado para URL.

Captura de pantalla de mi error

y cuando recibo ese error, mi página se queda en blanco.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Lo arreglé devolviendo observable de falso

 return this._auth.validate() .map((isValidated) => { if (isValidated && localStorage.getItem('authToken') && this.checkCookie()) { return true; } }).catch(() => { this.router.navigate(['/login']); return Observable.of(false); });
over 4 years ago · Santiago Trujillo Report

0

necesita usar una captura, y la captura tiene que devolver un observable.

 validate() { return this.http.get(this._apiEndPoint.validate) .map( (response: Response) => { const result = response.json(); // check authentication status from response return result.authenticated; }) .catch(error => Observable.throw(error)); // If you want to throw nothing, then return Observable.empty() }
over 4 years ago · Santiago Trujillo 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!