Menu

Three providers, three error formats: normalising them into one honest message
πŸ“°

Three providers, three error formats: normalising them into one honest message

DEV Community: phpΒ·Mobeen AhmedΒ·5 days ago
#yBrig6pw
#devto#dev#provider#message#visitor
Reading 0:00
15s threshold

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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.