noel-friedrich / terminal

Terminal-style Personal Homepage
https://noel-friedrich.de/terminal
MIT License
44 stars 6 forks source link

updating highscores. #18

Open lvlask opened 7 months ago

lvlask commented 7 months ago

Greetings Noel. What a beautiful project!

i was wondering how is it possible that scores gets uploaded. Exmp:

guess: 708 you got it! it took you 7 tries [highscores] Do you want to upload your score? [y/N] y [highscores] Your name: Melisa Tip: You can set your username permanently using name set Mahdi SyntaxError: Unexpected token '<', " <h"... is not valid JSON

that's what it shows once scored. Appericate if you help me out with it! Danke!

noel-friedrich commented 7 months ago

I’m unsure what the cause could be for this. I can’t reproduce the bug in my browser, it works for me (uploading a Highscore for the number-guess game).

I am noticing two things:

  1. The error must result from the Highscore-API not returning a valid JSON in your browser (here is the link to that api). However, this should be a server side issue, which would mean that it would also happen when I test it out. However, it works for me. It could be that the server temporarily had some issue, e.g. because the underlying database was busy or unable to respond properly. This issue should however be resolved now?
  2. In the output you copied, it says that you typed in the name Melisa, however it suggested that it set your name permanently to Mahdi. Is this a copy mistake or is there a bug happening somewhere? I can’t reproduce that either.

If the issue persists, I’d be happy if you could provide a few more details:

  1. The browser and operating system you’re using
    • Perhaps try switching to another browser (newest version of chrome?) and test if the issue persists?
  2. Perhaps you could open the provided link (this one) in your browser and show me what you see?
  3. If you’re able to, open your browsers dev tools and look at the network request corresponding to the error and look at the preview for the request to …/get_highscores.php. Does it look like valid JSON?
linuxchr commented 4 months ago

I could reproduce the error by taking away access to the API and then doing a request eg.

  1. Blocking the path on browser level
  2. Hosting an own development server where the relative path would be wrong.
noel-friedrich commented 4 months ago

Makes sense. I was concerned it might have something to do with my php outputting something shady (happy to be wrong here!).

Fixed the issue by adding a custom error message telling the user the potential cause directly (see commit 147d791). Hope this helps!