Closed transistive closed 2 years ago
Can you override Exception __construct this way?
public Exception::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)
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
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
andgetServerErrorCode
methods to the class. The class should then have a constructor looking like this: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.