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

138
Views
How to clear and sanitize complex objects or any object in javascript

I'm trying to log every possible error to a firestore document, to achieve this, I have a function which receives the error object, and saves it to the firestore document... the thing is... that this error object can be anything, it can be a single string and not an object, or it could be a complex object, appearently with functions aswell, but firestore won't accept some data types, for example if the object has an undefined property firestore will not accept it...

So I'm trying to find a way to sanitize or clean an object from which I don't know what properties could have.

Right now i'm using this:

import {db} from 'src/firebase/config'
import { addDoc, collection } from 'firebase/firestore';
import {Platform} from 'quasar'

export const saveErrorLog = async (hotel, uid, ref, error) => {
  const guestRef = collection(db, 'error_logs');
  const cleanErrorObject = Object.entries(error).reduce((a,[k,v]) => (v ? (a[k]=v, a) : a), {})
  const logData = {
    platform: Platform.is || null,
    ref: ref || null,
    error: { ...cleanErrorObject },
    hotel: hotel || null,
    uid: uid || null
  }
  await addDoc( guestRef, logData )
}

This works most of the time, but sometimes firebase returns the same error of unsupported data types... I think it is because some error objects have functions aswell, but I'm not sure about it.

Thanks in advance.

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