How to handle state of a toggle switch?

I'm wondering about how to create a useful implementation of a toggle switch.

(think iOS style: enter image description here)

It is meant to be used in web applications. Because of that, an important point is, that after switching the toggle on/off in the UI, a request is send to the server, then (sooner or later) the server responds, if the action succeeded or not (via asynchronous JavaScript).

So I used the search and found a similar question with an accepted answer:

Toggle Switch with Delayed State Change

A loading animation while waiting is of course a good idea.

But my question is:

How to handle a failed request?