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
SoapFault exception cannot be caught when using SoapClient in Laravel #6618
Comments
Are you in a namespaced file that has already included |
Thanks for your response. SoapFault is an exception thrown by PHP SoapClient class (http://php.net/manual/en/class.soapfault.php). I have tried adding backslash but that didn't help. What I have found is that the SOAP exception is thrown and I can catch it, however, Laravel still crashes with FATAL SOAP exception. I have implemented the following workaround in my global.php to fix the issue temporarily.
|
If you catch all exception instead of catch try {
$client = new SoapClient("wsdl-url-here", ['trace' => 1, 'exceptions' => true]);
} catch (Exception $e) {
echo 'Catch it!';
} |
I have tried that as well, it still crashed with FATAL exception. |
Can you paste the complete exception's message? |
When I use invalid WSDL URL, this is the message I get without using any workaround: Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) |
Do you want to throw a backslash in front of @RomainLanz's solution too, the catch statement really should pickup on that exception. |
@dwightwatson He said that he tried: "I have tried adding backslash but that didn't help." |
Yes, tried both Exception and \Exception and get the same error as before. |
I was under the impression he had added a backslash to the |
I am wondering if I am having the issue outlined here: https://bugs.php.net/bug.php?id=47584 |
I believe the Homestead environment has XDebug but that isn't anything specific to Laravel. Looks like that bug could be the cause of your grief unfortunately. |
I am actually using XAMPP and have disabled xdebug completely in my php.ini, and that's why I was thinking it could be a Laravel issue. FYI- I tried the try/catch outside of Laravel within the same XAMPP environment and it works as expected (no FATAL crash) |
Laravel think that |
Set your |
Same problem here "Symfony\Component\Debug\Exception\FatalErrorException' with message 'SOAP-ERROR: Parsing WSDL: Couldn't load from http:...." |
You have to disable your error_handler. I got this problem when i was coding my own framework. The error_handler by passing the try...catch. |
Have you tried catching \Exception instead of a \SoapFault? |
My workaround in App\Exceptions\Handler for console application:
|
Actually, the try {
return $this->client = new SoapClient($this->getWsdlUrl(), [
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true
]);
} catch (SoapFault $exception) {
Log::error($exception);
error_clear_last(); // The solution.
} Tested in Laravel 5.2. EDIT: Still working in Laravel 5.7. Also, updated comment to use set_error_handler('var_dump', 0); // Never called because of empty mask.
@trigger_error("");
restore_error_handler(); |
Have you tried catching \Throwable instead of a \SoapFault? |
hi
This is working solution, soap thow exception and error than can not be catch.
Less code. |
The solution is to actually ask the Soap client to throw a SoapFault instead of reporting an E_ERROR. When the Soap client reports an E_ERROR, there is nothing for you to catch. To fix this initialise you SoapClient like this: $clientOptions = array(
'exceptions' => true,
);
try {
$client = new \SoapClient("foo.wsdl", $clientOptions);
} catch (\SoapFault $e) {
// Do what you need to do!;
}
try {
$result = $client->__soapCall($method, $data);
} catch (\SoapFault $e) {
// Do what you need to do!;
} |
This is the correct solution. Thank you. |
Have you tried this? It doesn't actually work. In fact I've tried every single workaround on this issue, nothing actually works. Bumping this issue, this is an ongoing problem even in 6.4. We need a reasonable way to override Laravel's exception handling. |
1st step: Make sure you include 2nd step: 3rd step: I had to change his code a little. Added a backslach like this "...} catch (\SoapFault $exception) {..." |
When using When using Any idea how I can get to |
In the example above, if I have invalid WSDL URL, I am supposed to get SoapFault exception since I set exceptions to true. However, Laravel catches this as FATAL exception and the application crashes. This code works as expected outside of Laravel.
The text was updated successfully, but these errors were encountered: