0
votes

In the below code, while I'm trying to insert data into firebase Firestore, the data gets inserted but on returning promise, it returns error as INTERNAL Error. Hera is the console logged Error

Error: INTERNAL
at new f (error.ts:66)
at y (error.ts:175)
at O.<anonymous> (service.ts:231)
at tslib.es6.js:100
at Object.next (tslib.es6.js:81)
at r (tslib.es6.js:71) "INTERNAL"

The Code in Cloud Functions (index.js)

exports.addNewBook = functions.https.onCall((data, context) => {
    return admin.firestore().collection('books').add(data.book)
        .then((doc) => { return doc })
        .catch((error) => { return error });
});

The Client Function invoking the Cloud Function (Client Function)

const addNewBooks = (formData) => {
   bookData = {
      no: formData.bookNo.value,
      name: formData.bookName.value,
      author: formData.bookAuthor.value,
      publisher: formData.bookPublisher.value,
      librarian: formData.librarianName.value
   }
   console.log(bookData);
   const addBooksToDb = firebase.functions().httpsCallable('addNewBook');
   addBooksToDb({
         book: bookData
      })
      .then(doc => {
         console.log(doc, doc.id)
      })
      .catch(error => {
         console.log(error, error.message)
      });
}


$("#addBookModalForm").submit(function(e) {
   e.preventDefault();
   addNewBooks(this);
   this.reset();
});

Error logged on Cloud Functions on console.log() in index.js

    addNewBook
    Unhandled error RangeError: Maximum call stack size exceeded 
        at isArrayLike (/srv/node_modules/lodash/lodash.js:11333:31)
        at keys (/srv/node_modules/lodash/lodash.js:13307:14)
        at /srv/node_modules/lodash/lodash.js:4900:21
        at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
        at Function.mapValues (/srv/node_modules/lodash/lodash.js:13400:7)
        at encode (/srv/node_modules/firebase-functions/lib/providers/https.js:179:18)
        at /srv/node_modules/lodash/lodash.js:13401:38
        at /srv/node_modules/lodash/lodash.js:4905:15
        at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
        at Function.mapValues (/srv/node_modules/lodash/lodash.js:13400:7)

What is the reason for throwing an INTERNAL Error

1

1 Answers

0
votes

The promise returned from add() probably rejected and generated an error. If you don't take care to send a specific, known response to the client, you could see an error on the client.

Since we can't see the exact inputs and outputs (you are just showing variables here), and the log output, we have no way of knowing exactly what happened, so you will have to debug this to figure out what went wrong.