HTTP assuming .txt is .json

Hey all,

Having a bit of an issue with the following:

httpClient.get('../../assets/store/GenerateInitialViolations.txt').map((res: Response) => res.text()).subscribe(data => {

I’m getting a response when debugging:

{error: SyntaxError: Unexpected token I in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttp…, text: "Insert into violations ( VIC_UID, VIC_LEGAL_DESCRI… Non-respect cond/restrict permis", 500, VFHM113)"}

It looks like it’s treating it as a JSON file for some reason and having a panic when it’s not in the right form. How do I fix this so I can read from this plant .txt file and just get it’s text?

Maybe by setting the response type to text?

httpClient.get('../../ass...tions.txt', {responseType: 'text'}).map...

Edit: ignore the following, found the documentation and realized I was over-complicating it.

Hey! Made progress there.
I’m a bit new to the environment. I’m getting that res.Text() isn’t a function. Looks like it should be though, is there something I’m missing here?
Feel a little silly asking, I’m having trouble finding the API for “Response” or where I could confirm this myself.

1 Like