Skip to content

Commit a4cf6cd

Browse files
author
Matias Melograno
committed
added error handling on manager
1 parent 1d8e593 commit a4cf6cd

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

src/SplitIO/Sdk/Manager/SplitManager.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,30 @@ class SplitManager implements SplitManagerInterface
1313
{
1414
public function splitNames()
1515
{
16-
$cache = new SplitCache();
17-
return $cache->getSplitNames();
16+
try {
17+
$cache = new SplitCache();
18+
return $cache->getSplitNames();
19+
} catch (\Exception $e) {
20+
SplitApp::logger()->critical('splitNames method is throwing exceptions');
21+
SplitApp::logger()->critical($e->getMessage());
22+
return [];
23+
}
1824
}
1925

2026
/**
2127
* @return array
2228
*/
2329
public function splits()
2430
{
25-
$cache = new SplitCache();
26-
$rawSplits = $cache->getAllSplits();
27-
return array_map('self::parseSplitView', $rawSplits);
31+
try {
32+
$cache = new SplitCache();
33+
$rawSplits = $cache->getAllSplits();
34+
return array_map('self::parseSplitView', $rawSplits);
35+
} catch (\Exception $e) {
36+
SplitApp::logger()->critical('splits method is throwing exceptions');
37+
SplitApp::logger()->critical($e->getMessage());
38+
return [];
39+
}
2840
}
2941

3042
/**
@@ -33,20 +45,26 @@ public function splits()
3345
*/
3446
public function split($featureName)
3547
{
36-
$featureName = InputValidator::validateFeatureName($featureName, 'split');
37-
if (is_null($featureName)) {
38-
return null;
39-
}
48+
try {
49+
$featureName = InputValidator::validateFeatureName($featureName, 'split');
50+
if (is_null($featureName)) {
51+
return null;
52+
}
4053

41-
$cache = new SplitCache();
42-
$raw = $cache->getSplit($featureName);
43-
if (is_null($raw)) {
44-
SplitApp::logger()->warning("split: you passed " . $featureName
45-
. " that does not exist in this environment, please double check what Splits exist"
46-
. " in the web console.");
54+
$cache = new SplitCache();
55+
$raw = $cache->getSplit($featureName);
56+
if (is_null($raw)) {
57+
SplitApp::logger()->warning("split: you passed " . $featureName
58+
. " that does not exist in this environment, please double check what Splits exist"
59+
. " in the web console.");
60+
return null;
61+
}
62+
return self::parseSplitView($raw);
63+
} catch (\Exception $e) {
64+
SplitApp::logger()->critical('split method is throwing exceptions');
65+
SplitApp::logger()->critical($e->getMessage());
4766
return null;
4867
}
49-
return self::parseSplitView($raw);
5068
}
5169

5270
/**

0 commit comments

Comments
 (0)