How to setup HA without an error if an API fail

Is there a way to set up that if the one API fails to get any data then instead of the error, I can grab the latest working data into the loops? Is this possible? Let’s per se get covid19 API which is currently down?

What does that even mean?

Let per se… I have my google fit sync to HA. In most cases it will throw in SLEEP data, however, sometimes that data is not available and will throw an error. Is it possible if that information appears to be null, then HA could retrieve the old data instead?

Error Example:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1850
First occurred: 2:11:04 PM (40 occurrences)
Last logged: 2:36:19 PM

Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'deep_sleep' when rendering '{%- if states.sensor.richard_sleep.attributes.deep_sleep %} {{ states.sensor.richard_sleep.attributes.deep_sleep }} {% else %} {{ states.sensor.richard_sleep.attributes.deep_sleep }} {%- endif %}'
Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'light_sleep' when rendering '{%- if states.sensor.richard_sleep.attributes.light_sleep %} {{ states.sensor.richard_sleep.attributes.light_sleep }} {% else %} {{ states.sensor.richard_sleep.attributes.light_sleep }} {%- endif %}'
Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'bed_time' when rendering '{% if states.sensor.richard_sleep.attributes.bed_time %} {{ states.sensor.richard_sleep.attributes.bed_time }} {% else %} {{ states.sensor.richard_sleep.attributes.bed_time }} {% endif %}'
Template variable warning: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'wake_up_time' when rendering '{% if states.sensor.richard_sleep.attributes.wake_up_time %} {{ states.sensor.richard_sleep.attributes.wake_up_time }} {% else %} {{ states.sensor.richard_sleep.attributes.wake_up_time }} {% endif %}'