Rob's garden / notes / note

Note

I’m doing a large project migration and as part of it there is a legacy API so the same front end can use the old API. All while under the hood, there are new improved data types that take in the learnings from all the previous deployments.

The legacy api is neat and a bit hacky but the front end consumes it without question.

Apart from one endpoint that kept crashing out with JSON parsing errors. I’d meticulously gone through and made sure every request had the exact same response payload and have been stumped with it all evening.

Eventually I dug into the http fetch code to see what that was doing differently. That’s where I found out the http errors with the new API were not json! They were raw http requests using standardised status codes with often an empty body.

There was a previously complicated error structure using referencable tags you could lookup to see what went wrong. This was never useful and the front end basically ignored them. But if they weren’t there there was no json to parse and it throws errors.

So the long and short of it was that the legacy API now mimics the success AND errors of the old api and yep it’s working a treat again.