'Response from flask api giving json parse error in angular

Here my server which is written in flask is basically doing like getting documents from a firebase collection and sending that data(whole data) as a response. My firebase collection have like 9000 documents which I want to send as a response. Here is my flask code -

def getAllCredits(db):
    mainData = []

    try:

        collection = db.collection('Credits')
        docs = collection.stream()
        for index, doc in enumerate(docs):
            res = doc.to_dict()
            mainData.append({"id":doc.id,"data":res})
        print(len(mainData))
        return jsonify(mainData)

Although I am getting all the data as json successfully in postman but in angular I am getting json parsing error. Setting the response type to text is working but I need to get the data as json('Content-Type' also set to 'application/json'). Here is my angular code -

getAllCredits() {
    this.http.get('http://localhost:8080/getAllCredits')
      .subscribe(result => {
        console.log(result);
      })
  }

I am getting error like -

"Http failure during parsing for http://localhost:8080/getAllCredits"
SyntaxError: Unexpected token e in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4400/vendor.js:37062:51

Can anybody tell me what is the problem where? Creating the same api in nodejs is working perfectly fine and I am getting all the 9000 documents in angular(JSON parsed correctly). Don't know what is the issue in flask. I am setting the content-type correctly also. Is this issue related for the large data? Can anybody help me regarding this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source