Do Something after API Timeout

Hello,

I have an API that pings a server if the server is online it will return {"status":"online"} but obviously if the server is offline it won’t return anything so is there a possibility that I could edit data if the API times out. If so how?

Thanks