fetch('/my-api-endpoint')
  .then(response => {
    if (response.headers.get('cf-mitigated') === 'challenge') {
      // Handle challenged response
    } else {
      // Process response as usual
    }
  });