Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0


#1

Hello Cockpit Community ;

Any one to help me why am getting this error when i try to read my collections from cockpit.

Here is an error that am getting in the browser when i run the app.

Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0

Here is my react component where am reading my collection as JSON

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {

  constructor() {
    super();
      this.state={items:[]};
  }

  componentDidMount(){
    fetch('/api/collections/get/posts?token=6d6126a5613634a710aee0ddbadbe1')
    .then(res => res.json())
    .then(res => console.log(res));
  }

  render() {
  return(
    <div>
        {this.state.items.length ?
          this.state.items.map(item=><div key={item.id}>{item.body}</div>) 
          : <li>Loading...</li>
        }
    </div>
 )
}
}

export default App;

#2

Well; I found out the issue. The Issue was with the url that i was fetching data from was wrong as it was lacking a host ip address eg https://10.8.0.2/xxx/yyy?token=888d… so i updated the url and it worked fine.

Thanks!