My little downloader site talks to three different video APIs. One handles TikTok and Instagram, one handles Facebook, and one handles YouTube. They each do the same job β take a link, return a file β but when something goes wrong, they each complain in a completely different language. If I passed those errors straight through, my visitors would see three kinds of nonsense. So I built a small normaliser, and it turned out to be one of the most useful pieces of code on the site.
The problem
Here is what a failure actually looks like from each provider.
The all-in-one provider returns HTTP 200 with a body like {"status": "error", "msg": "Service is busy"} . The Facebook provider returns a proper HTTP 500 with {"error": "Failed to fetch video"} . The YouTube provider sometimes returns {"code": 429, "message": "Too many requests"} and sometimes an empty body with no JSON at all. Three providers, four shapes, and none of them say anything a normal visitor would understand.
Worse, the shapes change.β¦