How debugging can look like š
It is week 17 in the bootcamp, and we are diving into the backend sprint and learning how to build RESTful APIās. In order to do that I am working with a database. For my project I picked a database consisting of Netflix titles, each object contains 12 properties that I can use to define routes/endpoints (aka the path the user will take to find a specific Netflix title, or collection of Netflix titles based on the given key and value). Exciting! I know š.
In this database there is a unique id for each Netflix title and I wanted to create an endpoint that would lead the user to a specific Netflix title based on that id.
I started writing the endpoint below and used the array method find(), that would lead to a specific title. But for some reason, when testing this in the browser, it didnāt work, I just got my error status 404 ā No shows/movies found with that IDā.ā¦and so the detective work began šµļø. What was I missing ? Why could I not find that specific Netflix title? I needed to trace back, and go through my code step by step.
After going through the material, trying different alternatives, googling to figure this out, it turns out that the key show_id is a string. Even though at first glance it looks like numbers, it is in fact a string shown by a simple console.log ({show_id}).
To convert this from a string to a number, I just simply needed to add a + in front of the show_id on line 41.
And here you have it, a object found based on a unique ID!
It is crazy how much issue a tiny plus sign can cause, but when you finally solve it, you will feel amazing.ā¦.. nothing really beats this feeling and most importantly it is a lesson that stays. A natural part of the coding journey. Now on to finding my next lesson and bug to squishš!