Can't use exit(0), how else can I terminate a response?
You need to terminate using the kernel. You'll have to generate $currentRequest and $response, which may already be available depending on where your code lies. After you have them, you can terminate the request using:

\Drupal::service('kernel')-&gt;terminate($currentRequest, $response);