pradosoft / prado

Prado - Component Framework for PHP
Other
187 stars 70 forks source link

#948 TException adds support for PHP's integer Exception::Code #949

Closed belisoful closed 1 year ago

belisoful commented 1 year ago

By appending "=NN" to the errorMessageCode the integer error Code can be set.

This also adds the TNetworkException and TSocketException.

belisoful commented 1 year ago

The error templates need to be updated for Error Codes but that is another revision.

belisoful commented 1 year ago

I actually agree with you on the hackiness. I wasn't expecting this to be accepted as is.

Your parameter overriding is similar to the Throwable for $previous chaining of exceptions. I love it. I'll patch it up.

belisoful commented 1 year ago

It does reverse the Exception parameters for message and code, but its an acceptable quirk (for now).

belisoful commented 1 year ago

FYI, I'm updating the PHPDoc for this change, so it's taking a few moments more than usual.

Also. this is the code that fits:

public function __construct($errorCode, $errorMessage = null, ...$args)
    {
        if(!is_int($errorCode)) {
            //assume old code
            if ($errorMessage !== null || !empty($args)) {
                array_unshift($args, $errorMessage);
            }
            $errorMessage = $errorCode;
            $errorCode = 0;
        }

because there may not be a second parameter in the old style, which is fine.

belisoful commented 1 year ago

OK. Ready for review.

Keep in mind that the error template might need updating with the %%ErrorCode%% token.