Sudoku Solver : [SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON]

I stumbled across this error when testing my unfinished project (Sudoku Solver / Quality Assurance)

As I understand, because of server error - instead of JSON, HTML is being sent (as response). Error points to fetch() method.

No clue how to solve this :face_with_spiral_eyes:

api.js :

'use strict';

const SudokuSolver = require('../controllers/sudoku-solver.js');

module.exports = function (app) {
  let solver = new SudokuSolver();

    .post((req, res) => {
      let puzzle = req.body.puzzle
      let coordinate = req.body.coordinate
      let rowCoor = coordinate[0]
      let colCoor = coordinate[1]
      let value = req.body.value

      let conflict = [];

      // check rows
      if (solver.checkRowPlacement(puzzle, rowCoor, colCoor, value)) {

      // check columnns
      if (solver.checkColPlacement(puzzle, rowCoor, colCoor, value)) {

      // check region
      if (solver.checkRegionPlacement(puzzle, coordinate, value)){

      // generate response
      if (conflict.length === 0) {
          valid: true

      } else {
          valid: false,
          conflict: conflict

    .post((req, res) => {
      let puzzle = req.body.puzzle
      let output = solver.validate(puzzle)

        ? res.json({error: output}) 
        : res.json({error: "no error"})

I think we need to see all of the code. Post a repo with it.

I assume the 500 is causing an HTML response instead of a JSON response. Not sure what is causing the server to throw.

thx for responding.

It is throwing on line 222. You should be able to figure out why if you debug it. Look at what indexOf is returning before it.

1 Like