How can I ignore the timeout exception #19
-
|
Hi Stefan Zweifel, Thank you for the great package! Is there any way to ignore the timeout exception from Browershot? I cannot ignore the |
Beta Was this translation helpful? Give feedback.
Answered by
stefanzweifel
Jul 3, 2022
Replies: 1 comment 1 reply
-
|
Hey The problem is that there is no dedicated use Hammerstone\Sidecar\Exceptions\LambdaExecutionException;
use Illuminate\Support\Str;
use Spatie\Browsershot\Browsershot;
use Wnx\SidecarBrowsershot\BrowsershotLambda;
try {
$screenshot = BrowsershotLambda::url('https://github.com')
->base64Screenshot();
} catch (LambdaExecutionException $exception) {
// Check if the Exception Message contains "TimeoutError".
// If so, fallback to the local Browsershot instance.
// Or you can do something else.
if (Str::contains($exception->getMessage(), 'TimeoutError: Navigation timeout of')) {
$screenshot = Browsershot::url('https://github.com')
->base64Screenshot();
} else {
// Rethrow the exception to be handled by the default Laravel Exception Handler
throw $exception;
}
}By checking the message of the LambdaExecutionException you can fine tune your exception handling. If it isn't a TimeoutError, just rethrow the exception and let Laravel handle the exception like every other exception. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
phuclh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey
The problem is that there is no dedicated
TimeoutExceptionin Browsershot. What you could do is this: