Translating error messages from an external API

apierror messagesinternationalization

If I am localizing a piece of software that uses an external API, how should I handle error messages that originate in this API? I do not control the API, I only consume it. The error responses are not very structured: some contain error codes, some contain verbose details in the text, others almost nothing. Some errors can be fixed by the user (incorrect configuration), some are caused by the external service (server overload), some could be caused by a bug in my software (of course, this would be very unlikely…).

I would like to provide a smooth experience to my end-users, so they know what went wrong and what they can do to fix it. What is the best strategy to use here?

(This is a generalization of a question from the WordPress Stack Exchange. I thought it would be worth re-asking here, because it is not limited to WordPress plugins.)

Best Answer

You're looking for the Adapter Pattern. I always wrap an external API otherwise it leaks into the rest of the application (your problem with error codes is a good example).

Related Topic