Should I throw exceptions in a Trigger?

Which of the below is the acceptable way to do what I am trying to accomplish?

exports.onExecutePostLogin = async (event, api) => {

    const ApiKey = event.secrets.CIVICRM_API_KEY;

    // Should I do this?
    if (!ApiKey) {
        console.log( `APIKEY is not configured` );
        api.access.deny('APIKEY is not configured');
        return;
    }

    // Or this?
    if (!ApiKey) {
        throw new Error('APIKEY is not configured');
    }

};

The first approach using api.access.deny() is more appropriate here because:

  1. It uses the provided API mechanism to properly handle authentication failures
  2. It logs the error for debugging
  3. It explicitly denies access through the authentication system
  4. It maintains better control flow

The throw new Error() approach would:

  1. Crash the execution without proper error handling
  2. Not leverage the authentication API’s built-in functionality
  3. Miss logging the failure
  1. It maintains better control flow

I have another thread asking about this that no one replied to yet. Maybe you can answer it.

Essentially, can I call api.access.deny() anywhere in my code and essentially process.exit(1) happens? Because if I throw an Exception we come to a full stop and I dont have potentially undefined things being passed around (which ultimately leads to a less discoverable exception thrown).