peckish icon indicating copy to clipboard operation
peckish copied to clipboard

Unrecognised token '<' error

Open rahulbhankar786 opened this issue 7 years ago • 1 comments

{ [SyntaxError: JSON Parse error: Unrecognized token '<'] line: 10658, column: 14, sourceURL: 'http://11.0.8.2:8081/index.bundle?platform=android&dev=true&minify=false' }

url: http://www.recipepuppy.com/recipes/findByIngredients//?ingredients=bacon%2C%20cucumber%2C%20banana&fillIngredients=false&limitLicense=false&number=20&ranking=1 giving me 404 page not found

image

rahulbhankar786 avatar Dec 22 '17 05:12 rahulbhankar786

@rahulbhankar786, that's because the api path and param names have changed. Make the following changes to api.js and recipes.js actions:

api.js:

static xhr(route, params, verb) {
  const host = 'http://www.recipepuppy.com/api'
  const url = `${host}${route}`
  let options = Object.assign({ method: verb }, params ? { body: JSON.stringify(params) } : null );
  options.headers = Api.headers()
  return fetch(url, options).then( resp => {
    let json = resp.json();
    if (resp.ok) {
      return json
    }
    return json.then(err => {throw err});
  }).then( json => json.results );
}

recipes.js actions:

export function fetchRecipes(ingredients) {
  return (dispatch, getState) => {
    const params = [
      `i=${encodeURIComponent(ingredients)}`,
    ].join('&');
    return Api.get(`/?${params}`)
      .then(resp => {
        console.log(resp);
      })
      .catch(err => {
        console.log(err);
      })
  };
}

KRUBERLICK avatar Mar 01 '18 12:03 KRUBERLICK