Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add capability to Ignore Exceptions if Broadcast fails #38860

Closed
wants to merge 1 commit into from
Closed

[9.x] Add capability to Ignore Exceptions if Broadcast fails #38860

wants to merge 1 commit into from

Conversation

xiCO2k
Copy link
Contributor

@xiCO2k xiCO2k commented Sep 18, 2021

Description

This PR normalizes all the Exceptions under the broadcast drivers, Ably, Pusher, Redis to return only a BroadcastException.

Also adds the capability to ignore exceptions in the case of the broadcast fails to send, I find myself having to add a way to ignore the broadcast exceptions to avoid the user to receive a 500 error.

Proposal addition to the broadcasting.php config:

    /*
    |--------------------------------------------------------------------------
    | Ignore Exceptions
    |--------------------------------------------------------------------------
    |
    | Here you can set to ignore all the exceptions, in the case something
    | happens to your connection it will not throw an exception.
    |
    */

    'ignore_exceptions' => false,

@xiCO2k
Copy link
Contributor Author

xiCO2k commented Sep 18, 2021

I have tests to add to this PR, but I can't figure how to mock an exception, Example:

public function testItReturnsBroadcastExceptionIfConnectionFails()
{
    $this->assertException(BroadcastException::class);

    m:mock('Pusher\ApiErrorException', \Exception::class);
    $this->pusher->shouldReceive('trigger')
                 ->once()
                 ->andThrow(\Pusher\ApiErrorException::class);

    $this->broadcaster->broadcast(['test-channel'], 'test-event', ['name' => 'Taylor']);
}

It does not allow to mock the exception like this.

Any ideas?

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@taylorotwell
Copy link
Member

Don't hate the idea but not a big fan of the implementation.

@xiCO2k
Copy link
Contributor Author

xiCO2k commented Sep 18, 2021

Got it, I guess the normalize to the BroadcastException, is good, but where that is set the ignore_exceptions you don't like it.

Thanks @taylorotwell.

@caiokawasaki
Copy link
Contributor

I really liked this, I have the same problem with redis queues, sometimes i get: socket error on read socket

It would be nice if I could skip this without a try catch.

@xiCO2k
Copy link
Contributor Author

xiCO2k commented Sep 18, 2021

@caiokawasaki Yes, I have that problem a lot, even pusher sometimes fails.

If there is any ideas to improve the implementation, let me know.

Since this one will not be merged as it is, also added a new pull request just to normalize all to BroadcastException. check #38862.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants