Should I retry a request if it returns an error?

Generally, no, not if using an Ably client library to make the request.


Most errors are 4xx, meaning that something is wrong with the request. In this case, retrying is not indicated as it's unlikely to give a different result. (And always retrying a request which is badly formed will just result in it failing every time, leading to an infinite retry loop, which can result in a single client using up your package's API request limit and so affecting your other clients).


Occasionally there may be a 5xx error (meaning a problem at our end). Retrying can be indicated for these -- but the Ably client libraries handle that themselves. They will autonomously retry the request up to three times to different endpoints (which resolve to different datacenters worldwide, in case the problem is with dns, or isolated to a particular datacenter) before returning (or in the case of async libraries, calling the callback supplied). So you don't need to do anything yourself; the Ably client library abstracts that away.