Angular 8 NgRx - Issue: Uncovered action that cannot be serialized

In order to include a global Error object in my app state, I implemented an http interceptor to trigger the setError action:

export interface IlgError {
  message: string;
  responseError: HttpErrorResponse;
}

export const setError = createAction("[Global] Error Occurred", props<{ errorObj: IlgError }>());

However, upon dispatching this action, an error message is returned:

Error: Detected unserializable action at "errorObj.responseError"

The configuration for my app module looks like this:

StoreRouterConnectingModule.forRoot({ routerState: RouterState.Minimal }),

I am trying to understand what it means by "unserializable". Is there a way to disable this for specific actions?

Answer №1

It seems like the issue is originating from the following line:

 props<{ errorObj: IlgError }>

My suggestion would be to store a plain object in your store similar to this:

export const login = createAction(
    '[Login Page] Login',
    props<{username: string; password: string;}>(),
)

Answer №2

To resolve the issue, one option is to pass an object with properties in the props object. However, this approach can become complicated when dealing with a large number of properties in the object.

A more efficient solution would be to define the action as follows:

export const login = createAction(
 '[Login Page] Login',
  props<IlgError>(),
)

Then, you can use the following code to dispatch the action:

  loadMovies$ = createEffect(() => this.actions$.pipe(
    ofType('[Login Page] Login'),
    mergeMap(() => this.moviesService.getAll()
      .pipe(
        map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
        catchError((error: IlgError) => of(failureAction(error)),)
      ))
    )
  );

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

Unable to retrieve the object property despite its presence

Within my React component, I have implemented a feature that retrieves a user's written story from the backend. The JSON data is stored in a variable called storyState. Despite seeing all the necessary properties like "title" when logging the data, I ...

What is the process for obtaining the home directory path of a computer using JavaScript?

I am inquiring about how to obtain the home directory path of a computer using AngularJS or JavaScript. An example of this would be C:\Users\<username>. ...

The name field in the request body is currently undefined

Currently, I am working on developing a basic blog page using technologies such as ejs, JavaScript, Node.js, Express, and body-parser. While working on passing inputs to the command line, specifically for the title, I encountered an issue. When I used req ...

Difficulty accessing `evt.target.value` with `RaisedButton` in ReactJS Material UI

My goal is to update a state by submitting a value through a button click. Everything works perfectly when using the HTML input element. However, when I switch to the Material UI RaisedButton, the value isn't passed at all. Can someone help me identif ...

Generate a series of inquiries from an API response and display them dynamically, complete with a text field and radio button for each question

Currently, I am in the process of developing a Question/Answer page using ReactJS. The questions are retrieved through an API call. I aim to present a series of radio buttons and text fields for users to respond to these questions. A "Panel" that resemble ...

What is the best way to resend a request once the token has been refreshed?

Imagine this scenario: I make a request to retrieve some data, but the response indicates that the token has expired. In such cases, I need to update the token and then resend the original request. How can I achieve this using redux-toolkit and middleware? ...

Integrate jQuery into your Spring MVC application

Struggling to integrate jQuery into my Spring MVC application as a beginner in Spring MVC. I've created a 'js' folder under the webapp directory, but unsure how to include the file in my view. I attempted: <script type="text/javascript" ...

Issue with Redirect URI in Angular application causing authentication problems for Strapi and Microsoft integration

After carefully following the instructions outlined in this guide, I have configured all settings related to the App Registration, Strapi Provider, and MSAL. However, when the authentication process initiates, I am directed to a Microsoft login screen wher ...

Utilizing Conditional Statements in the @artsy/fresnel Framework

I recently started working on a responsive React application using the @artsy/fresnel npm package. Below is a snippet of the code I have implemented: <Media greaterThanOrEqual='computer'> <div style={{ padding: '20px 50px' ...

:host-selector for Angular Material dialog

I am currently working with a dialog component provided by angular-material and I need to customize the appearance of the popup dialog. I am aware that there is some support for styling through the component generation: let dialogRef = dialog.open(MyDi ...

The use of PartialLinkText is ineffective when utilized in TypeScript

Below is a list of elements: <div class="container-menu" _ngcontent-c13=""> <nav _ngcontent-c13=""> <ul _ngcontent-c13=""> <li _ngcontent-c13=""> <a class="" _ngcontent-c13="" href="/32info" role="link" routerlinkactive="active" ...

Why is my node.js react app failing to detect the index.html file?

Take a look at the app here: git repository The issue I'm facing is that index.html doesn't seem to be properly linked, resulting in: 1) The website not being responsive for mobile devices 2) Lack of a favicon https://i.sstatic.net/l4hHJ.png ...

Having trouble dealing with the response following $resource.save in AngularJS, specifically expecting JSON data

Hi there, thank you so much for your help! I'm just starting out with Angular and I'm facing some challenges trying to consume data from an API for my application. The main issue I'm encountering is related to CORS: In order to run a local ...

SQL message comparison error within mysql module is malfunctioning

Currently, I am utilizing the nodejs MySQL module to automatically create a table every month. To ensure this process runs smoothly, I need to check if the table already exists using the condition err.sqlMessage == Table 'tableName' alre ...

The Javascript function is malfunctioning, unable to assign the 'onclick' property to null

Here's the code snippet I'm working with: var exit = document.getElementById("exit"); exit.onclick = function() { "use strict"; document.getElementById("fadedDiv").style.display = "none" ; }; However, when I check the console, it shows ...

Your search parameter is not formatted correctly

I am currently working on filtering a collection based on different fields such as name by extracting the values from the URL parameters. For example: http://localhost:3000/patient?filter=name:jack I have implemented a method to retrieve and convert these ...

Top tips for accessing a file that has been uploaded using the $http service and the HTML5

I've encountered an issue while trying to upload an image within an Angular application. Here's the code snippet in question: var f = document.getElementById('product-image').files[0], r = new FileReader(); r.onload ...

Encountering an issue with Sails.js while attempting to connect to a cloud-based

When using cloud MongoDB with a sails adapter, I encountered an error while running the app. Can someone assist me in resolving this issue? default: { adapter: 'sails-mongo', url: 'mongodb://USERNAME:<a href="/cdn-cgi/l/email-protec ...

Creating effective test cases for Angular JS controllers

Our team has recently taken on the task of writing test cases for our application, specifically focusing on controllers. Utilizing Mocha, Chai, and Sinon libraries, we are looking for guidance on how to effectively write these test cases. We have shared a ...

To begin, formulating a blank state entity containing a collection of key-value pairs with JSON objects as the values. Subsequently, modifying the contents of

I am working on setting up a reactJS state with an empty array to start. When I receive a message in the form of a JSON object, I want to add a key-value pair to the array, using the received message as the value and a specified key. For example: We have ...