Skip to content

Commit 2f1d086

Browse files
68: add top level try catch to not propagate internal rollbar exceptions to user apps
1 parent 0b3f13f commit 2f1d086

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/RollbarServiceProvider.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,36 @@ public function boot()
2828

2929
// Listen to log messages.
3030
$app['log']->listen(function () use ($app) {
31-
$args = func_get_args();
32-
33-
// Laravel 5.4 returns a MessageLogged instance only
34-
if (count($args) == 1) {
35-
$level = $args[0]->level;
36-
$message = $args[0]->message;
37-
$context = $args[0]->context;
38-
} else {
39-
$level = $args[0];
40-
$message = $args[1];
41-
$context = $args[2];
42-
}
43-
44-
if (strpos($message, 'Unable to send messages to Rollbar API. Produced response: ') !== false) {
45-
return;
46-
}
47-
48-
$result = $app[RollbarLogHandler::class]->log($level, $message, $context);
4931

50-
if (!$result || !$result->getStatus()) {
51-
\Log::error(
52-
'Unable to send messages to Rollbar API. Produced response: ' .
53-
print_r($result, true)
54-
);
32+
try {
33+
34+
$args = func_get_args();
35+
36+
// Laravel 5.4 returns a MessageLogged instance only
37+
if (count($args) == 1) {
38+
$level = $args[0]->level;
39+
$message = $args[0]->message;
40+
$context = $args[0]->context;
41+
} else {
42+
$level = $args[0];
43+
$message = $args[1];
44+
$context = $args[2];
45+
}
46+
47+
if (strpos($message, 'Unable to send messages to Rollbar API. Produced response: ') !== false) {
48+
return;
49+
}
50+
51+
$result = $app[RollbarLogHandler::class]->log($level, $message, $context);
52+
53+
if (!$result || !$result->getStatus()) {
54+
\Log::error(
55+
'Unable to send messages to Rollbar API. Produced response: ' .
56+
print_r($result, true)
57+
);
58+
}
59+
60+
} catch (\Exception $exception) {
5561
}
5662
});
5763
}

0 commit comments

Comments
 (0)