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

UPDATE: Solved it. Check bottom of post for solution

I’m currently passing all sudoku-logic tests but this one:

If the object submitted to /api/check is missing puzzle , coordinate or value , the returned value will be { error: 'Required field(s) missing' }

Test error message: [SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON]

It fails despite the fact that { error: 'Required field(s) missing' } is correctly displayed on the page, when running the three test cases fCC uses (one without coordinate, one without value, and one without puzzle).

It’s very disorienting because this test is almost the same as

If the object submitted to /api/solve is missing puzzle , the returned value will be { error: 'Required field missing' }

which passes. Furthermore, my code for both cases is almost exactly the same.
Routing snippet:

app.route('/api/check')
    .post((req, res) => {
      res.json( solver.checkPlacement(req.body.puzzle, req.body.coordinate.toUpperCase(), req.body.value) );
    });
    
  app.route('/api/solve')
    .post((req, res) => {
      // validate() IS CALLED INSIDE .solve() FIRST
      res.json(solver.solve(req.body.puzzle))
    });

Code for validate(), which works correctly and passes the test:

validate(puzzleString) {
    // CHECK IF STRING IS EMPTY
    if(!puzzleString){
      return {error: 'Required field missing'}
    }
[code continues]
}

Code for checkPlacement(), which works correctly and does not pass the test:

checkPlacement(puzzleString, coord, value) {
    // 1) CHECK IF ALL FIELDS HAVE INPUT
    if( !puzzleString || !coord || !value ){
      return { error: 'Required field(s) missing' }
    }
[code continues]
}

My best guess:

Because the JSON is correctly displayed, and going by the error message ( [SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON] ), my best guess is that something, somewhere is returning HTML instead of JSON, but I don’t see that anywhere. I thought this snippet from index.js could be relevant, as it handles the calls to both /api/solve and /api/check, but I don’t see any significant differences between the two, and the headers to both are set to "Content-type": "application/json". Also, I am running this project locally.

async function getSolved() {
  const stuff = {"puzzle": textArea.value}
  const data = await fetch("/api/solve", {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "Content-type": "application/json"
    },
    body: JSON.stringify(stuff)
  })
  const parsed = await data.json();
  if (parsed.error) {
    errorMsg.innerHTML = `<code>${JSON.stringify(parsed, null, 2)}</code>`;
    return
  }
  fillpuzzle(parsed.solution)
}

async function getChecked() {
  const stuff = {"puzzle": textArea.value, "coordinate": coordInput.value, "value": valInput.value}
    const data = await fetch("/api/check", {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "Content-type": "application/json"
    },
    body: JSON.stringify(stuff)
  })
  const parsed = await data.json();
  errorMsg.innerHTML = `<code>${JSON.stringify(parsed, null, 2)}</code>`;
}

I’ll appreciate any help I can get, as this particular issue doesn’t seem to be within the realm of the topics I’ve studied so far. Someone posted about running into the same issue previously, but I couldn’t find any answers on that post. If anyone finds it useful, here it is:

My Repo:

(it’s very unpolished though, lots of code I’ve yet to clean)

SOLUTION:

The problem was in this route:

app.route('/api/check')
    .post((req, res) => {
      res.json( solver.checkPlacement(req.body.puzzle, req.body.coordinate.toUpperCase(), req.body.value) );
    });

More specifically, the issue was the presence of .toUpperCase() as one of the arguments to the function. Once I removed it, the test passed. Still not exactly sure why that was a problem though.
I figured it out by looking at this part of the index.js file:

const stuff = {"puzzle": textArea.value, "coordinate": coordInput.value, "value": valInput.value}
    const data = await fetch("/api/check", {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "Content-type": "application/json"
    },
    body: JSON.stringify(stuff)
  })

Looking at it, I realized that, when calling /api/catch without any arguments, I was basically sending

body: {
"puzzle":  undefined,
"coordinate": undefined.toUpperCase(),
"value": undefined
}

I’m not sure why undefined.toUpperCase() (or is it null.toUpperCase()?) would cause the code to return HTML instead of JSON, but I can understand why it might not be a good idea to perform those kind of operations in the routes. Please someone correct me I’m wrong in my interpretation of the error,