4
connormon
197d

Accidentally JSON.stringified my data twice on the API call and couldn’t figure out why it wasn’t working. One API rewrite and two weeks later I spotted my mistake. Damn that was a shitty two weeks

Comments
  • 0
    I've been there - if there's too many libs, Middleware and api layers involved - a problem that would normally be a 5 minute debug session if you were fully familiar with the stack - can lead you to assume that some layer is doing implicit json stringifications.

    (I once used a fetch lib that changed it's response parsing for some domains and couldn't find that config)

    Did you learn anything specific from it? Like "if only I had logged all responses from that layer I would've found the issue"?
  • 1
    @jiraTicket It was a call to update a user. I’m using JS for the project and sent a fetch request to the API. It looked something like this:
    let updated user = JSON.stringify({
    //updated user
    });

    await fetch(url, {
    body: JSON.stringify(updatedUser)
    });

    So I didn’t really learn anything. I was just plain stupid. I think I wrote the request first and then wrote the actual updated user code and didn’t realize I already stringified it in the request.
  • 0
    @connormon Damn, that must have seemed super obvious in hindsight.

    Whenever I have an issue like this I will locally rewrite my code to multiple lines so that I can debug step (or console.log) the value after each step.

    Or debug with my colleague and usually I end up rubber ducking my way to a solution after reading my code out loud
Add Comment