neo4j-php / Bolt

PHP library to provide connectivity to graph database over TCP socket with Bolt specification
https://packagist.org/packages/stefanak-michal/bolt
MIT License
73 stars 10 forks source link

Improve MessageException for v3 #72

Closed transistive closed 2 years ago

transistive commented 2 years ago

Is your feature request related to a problem? Please describe. It is a shame the message and code during failure gets jumbled together as a single message. This makes it hard to extract the code and message again.

Describe the solution you'd like Add getServerErrorMessage and getServerErrorCode methods to the class. The class should then have a constructor looking like this:

public function __construct(string $serverMessage, string $severCode) {
    parent::__construct($serverMessage . '(' . $serverCode . ')');
}

This solution would not break backwards compatibility and provide a clean way for other libraries to keep the server code and message separated.

Describe alternatives you've considered The alternative as a library implementer right now is to extract the errorcode with a regex from the getMessage method, which is error-prone and cannot guarantee correctness.

stefanak-michal commented 2 years ago

Can you override Exception __construct this way?

public Exception::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)

https://www.php.net/manual/en/exception.construct.php

transistive commented 2 years ago

Yes, its a constructor which has other rules than normal methods. I do it all the time. It is of course just a suggestion, I can understand if you do not like the design decision so feel free to dismiss it

stefanak-michal commented 2 years ago

you are right https://www.php.net/manual/en/language.oop5.basic.php#language.oop.lsp