better error handling of cache header logic