unable to redirect through handlerror

I am attempting to redirect to an error component when the response data contains a "401" error. Below is my code snippet, but it seems that it is not properly handling the error. I have tried redirecting to an external URL without success. Any guidance would be greatly appreciated. Thank you in advance.

Service.ts:-

public searchGroups(searchReviewData: SurveillanceReviewSearchViewModel): Observable<SurveillanceReviewSearchViewModel> {
    this._urlSurveillanceDetails = this.baseHref + "/ReviewProfile/SearchGroups";
    const headers: HttpHeaders = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    let getData = this.http.post<SurveillanceReviewSearchViewModel>(this._urlSurveillanceDetails, searchReviewData, { headers: headers })
      .pipe(
        catchError(this.handleError)
      );
    return getData;
  }


  handleError(data: any) {
    if (data instanceof ErrorEvent) {

    }
    else {
      switch (data.errorResponse.httpStatusCode) {
       case 401:
       this.router.navigate(['error', 'unauthorized']);
         break;       

      }
    } 
    // return an observable with a user-facing error message
    return throwError(
      'Something bad happened; please try again later:' + JSON.stringify(data.errorResponse.httpStatusCode));

  }

Component.ts

searchGroups(searchReviewData: SurveillanceReviewSearchViewModel) {
    this._surveillanceService.searchGroups(searchReviewData).subscribe(data => {
      if (data != undefined) {
        this.reviewData = data;
        if (data.reviews != null) {
          if (data.reviews.length == 1) {                
            this.pagerSelectedData = data.reviews;
            this.loading = false;                

          }
        }
        else {
          this.loading = true;
        }
      }
    });
  }

ResponseJson from MVC controller:

{
    "loggedInUser": {
        "v2020UserId": "kdevisenakanthan"
    },
    "errorResponse": {
        "errorCode": null,
        "transactionId": null,
        "httpStatusCode": 401
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

uib-carousel glitching and stuck in never-ending loop

In my HTML, I have the following code snippet: <div style="height: 305px"> <div uib-carousel active="false" interval="50000" no-wrap="true"> <div uib-slide ng-repeat="slide in shoes track by slide._id" index="slide._id"> < ...

I'm having trouble retrieving the object value from a different function within my Typescript and Express application

Currently I am experimenting with utilizing typescript alongside express for my application development. I have created a function that I intend to utilize in various sections of my codebase. Upon invoking the function, I am able to observe the values thro ...

The timestamp will display a different date and time on the local system if it is generated using Go on AWS

My angular application is connected to a REST API built with golang. I have implemented a todo list feature where users can create todos for weekly or monthly tasks. When creating a todo, I use JavaScript to generate the first timestamp and submit it to th ...

Working with form data in PHP

There is an AJAX POST request originating from AngularJS, containing a JSON model with various fields and a file: ------WebKitFormBoundarywlEiXuTa9EkwFUWz Content-Disposition: form-data; name="model" {"fname":"and","lname":"and","email":"<a href="/cdn ...

Is it possible to manually activate a dropdown event using pure JavaScript?

I am attempting to manually trigger a dropdown event using JavaScript. Below is the function where I am trying to achieve this. I have successfully halted the initial event that occurs and now I need to initiate a dropdown event. stopNavigationTriggerDrop ...

Crafting a recursive Typescript Immutable.js Record through typing

I am currently working on representing a tree-like data structure using immutable js and typescript. At the moment, I am utilizing regular vanilla js objects to depict the nodes within the tree. Below is the type signature. type NodeType = { value: str ...

When you click on an element in Angular, it will not fade out as expected, instead displaying the error message "

After pressing the delete button in my twig file, the item is removed but it doesn't fade away as expected. I tried to seek help on this thread but couldn't comprehend the solution. Although the item is being deleted, I am encountering an error ...

Angular unit testing using Jasmin Karma encountered an error stating: "Unable to locate the name 'google'."

codeSnippet.js:- getAutocompleteResults(inputElement: ElementRef) { const autocomplete = new google.maps.places.Autocomplete(inputElement.nativeElement, { ... }); google.maps.event.addListener(autocomplete, 'place_changed&a ...

Angular 10: Display a notification when all checkboxes have been ticked

I am currently working on a project that involves Angular 10. The initial requirement was as follows: Users are presented with a list from which they need to choose one option using radio buttons. For example: the user selects covid19 from the given lis ...

What causes the website to malfunction when I refresh the page?

I utilized a Fuse template to construct my angular project. However, upon reloading the page, I encountered broken website elements. The error message displayed is as follows: Server Error 404 - File or directory not found. The resource you are looking fo ...

Develop a professional Angular application for deployment

Help! I'm struggling to build my Angular application for production. After running the 'ng build --prod' command, I can't find all my components in the 'dist' folder. Do I need to change or configure something else? I see som ...

Learn how to store the data from a FormArray into a MySQL database using Node.js

I am facing an issue and need assistance. Apologies for my limited English proficiency, but I will do my best to articulate the problem in hopes that you can assist me. Thank you. I am developing an activity management platform where employees log in ...

Tips for making a dynamic link button using Angular

I am currently working on creating responsive buttons that will navigate to specific pages using Angular routing. Here is my routing configuration: const routes: Routes = [ { path: 'home', component: HomeComponent}, { path: ' ...

Protractor timeout error triggered following completion of login process

Having an issue with testing the login procedure. Manual login works fine, but during automated tests I am unable to interact with the page after logging in (My page object model consists of three pages: homePage, loginPage, afterLoginPage). The third ex ...

Error: The function window.initMap is not defined in this context

I tried following a tutorial where I simply copied all the code https://developers.google.com/maps/documentation/javascript/tutorial However, I encountered an error stating that the initMap function is not recognized as a function. I am utilizing Angular ...

"Displaying array objects in a select dropdown menu - a step-by-step guide

I need assistance with displaying an array object in a select tag utilizing only AngularJS. Below is the structure of my array object: "matcherObject": { "Percentage Off": [ { "dealType": "Percentage Off", "subCategory": "16% to 20%", "recid ...

Complete and automatically submit a form in a view using AngularJS

I have developed a basic AngularJS application that is functioning smoothly. Currently, I am looking to populate certain fields and submit the form directly from the view without requiring any user input. Below, you'll find some simplified JavaScrip ...

Ways to conceal a div using ng-hide

Is there a way to make a div disappear using ng-hide? I have this code and I'm trying to hide the div with id="ApagarNA". The code displays a table with values, but some rows contain N.A in all 4 columns, and I want to hide those specific rows. For e ...

Simple steps to access a feature on an AngularJS application

I have my angular application stored in a variable (initialized with:) var app = angular.module('app', [...]); Now, I need to access the $timeout service. How can I retrieve this service from it? I am looking for something like: var timeout ...

Ensuring Mapael Functions Properly with Vite: A Guide

While some may question the usefulness of this post, I initially wrote it for my own benefit. However, if it can assist just one other person in a similar predicament, that would bring me great satisfaction. Like many Angular Developers, I too have been ea ...