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

Exception handler #16

Open
larsemil opened this issue Sep 4, 2018 · 4 comments
Open

Exception handler #16

larsemil opened this issue Sep 4, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@larsemil
Copy link

larsemil commented Sep 4, 2018

I would love to see a way to handle exceptions in a better way. I tried to implement it myself utilizing my own loop like this:

public function loop(){
        while(true) {
            try {
                $this->server->run();
            } catch (\Zend\Mail\Header\Exception\InvalidArgumentException $e){
                $this->log($e->getMessage());
                $this->log($e->getCode());
                $this->log($e->getFile().' line '.$e->getLine());
               
            }

        }
    }

But problem is that there is for now NO way to tell the client connecting that something went wrong.
It would be totally awesome if we could register an method to handle all exceptions from the server, which also would send the client for which the exception occurred. It could look something like this.

$server->addExceptionHandler(function ($exception, $client){
    $server->logger('something went wrong')
    $client->sendSyntaxErrorInParameters();
});

All in all - awesome package. :) 👍

@TheFox TheFox added the feature label Sep 4, 2018
@TheFox TheFox added this to the v0.8 milestone Sep 4, 2018
@TheFox TheFox self-assigned this Sep 4, 2018
@TheFox
Copy link
Owner

TheFox commented Sep 4, 2018

I like the idea. What do you expect to happen inside sendSyntaxErrorInParameters()? Which SMTP command should send the server to the client?

@larsemil
Copy link
Author

larsemil commented Sep 6, 2018

With an exceptionhandler like that where the client that got the exception is existing you can do whatever you want with the client.

if the clients methods are public that is. :)

@TheFox TheFox modified the milestones: v0.8, v1.0 Sep 9, 2018
@TheFox
Copy link
Owner

TheFox commented Sep 9, 2018

I just want to figure out how this actually can happen. How can I reproduce an \Zend\Mail\Header\Exception\InvalidArgumentException?

@TheFox
Copy link
Owner

TheFox commented Sep 9, 2018

@larsemil Please re-test it with the newest version in master.

This is not exactly what you wanted, but InvalidArgumentExceptions will now be catched and sendSyntaxErrorInParameters() will be called.

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

No branches or pull requests

2 participants