Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: "[object Object]" is not valid JSON #33

Open
tatianacue opened this issue Jan 14, 2025 · 0 comments · May be fixed by #34
Open

SyntaxError: "[object Object]" is not valid JSON #33

tatianacue opened this issue Jan 14, 2025 · 0 comments · May be fixed by #34

Comments

@tatianacue
Copy link

Hey I think I've come across an issue. When I try to fetch audits on an auditable model, it seems that if an audit entry's oldValues is null, it's unable to parse and it throws this error:

SyntaxError: "[object Object]" is not valid JSON at JSON.parse (<anonymous>) at Object.consume (file:///node_modules/@stouder-io/adonis-auditing/build/index.js:57:38)

Have I configured something wrong? I have tested this solution and it seems to have fixed it:

   consume: (value) => {
      if (!value) return null;
      if (typeof value === 'object') return value;  
      try {
        return JSON.parse(value); 
      } catch (e) {
        console.error("Failed to parse value:", value, e);
        return null
      }
    }
@tatianacue tatianacue linked a pull request Feb 5, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant