Skip to content

Commit 9b41bd0

Browse files
committed
Check for exceptions at each chunk stage
1 parent e8389ac commit 9b41bd0

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

Diff for: src/Lodestone/Http/Http.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Lodestone\Parser\Parser;
1010
use Ramsey\Uuid\Uuid;
1111
use Symfony\Component\HttpClient\CurlHttpClient;
12-
use Symfony\Component\HttpClient\Exception\ClientException;
1312

1413
class Http
1514
{
@@ -106,28 +105,30 @@ public function settle()
106105
$responses = AsyncHandler::get();
107106

108107
foreach ($client->stream($responses) as $response => $chunk) {
108+
// grab the user data
109+
$userdata = $response->getInfo('user_data');
110+
111+
// grab request id
112+
$requestId = $userdata['request_id'];
113+
114+
// if it wasn't a 200, return error
115+
if ($response->getStatusCode() != 200) {
116+
$content[$requestId] = (Object)[
117+
'Error' => true,
118+
'StatusCode' => $response->getStatusCode()
119+
];
120+
continue;
121+
}
122+
109123
if ($chunk->isLast()) {
110-
// grab the user data
111-
$userdata = $response->getInfo('user_data');
112-
113-
// grab request id
114-
$requestId = $userdata['request_id'];
115-
116124
// grab the parser class name
117125
/** @var Parser $parser */
118126
$parser = new $userdata['parser']($userdata);
119127

120-
try {
121-
// handle response
122-
$content[$requestId] = $parser->handle(
123-
$response->getContent()
124-
);
125-
} catch (ClientException $ex) {
126-
$content[$requestId] = (Object)[
127-
'Error' => true,
128-
'StatusCode' => $ex->getCode()
129-
];
130-
}
128+
// handle response
129+
$content[$requestId] = $parser->handle(
130+
$response->getContent()
131+
);
131132
}
132133
}
133134

Diff for: src/Lodestone/Parser/ParseCharacterClassJobs.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ public function handle(string $html)
8989
if ($fieldname == 'Elemental Level') {
9090
$elementalIndex = 0;
9191
} else {
92-
[$current, $max] = explode('/', $node->find('.character__job__exp')->text());
93-
$current = filter_var(trim(str_ireplace('-', null, $current)) ?: 0, FILTER_SANITIZE_NUMBER_INT);
92+
$bozjanString = trim($node->find('.character__job__exp')->text());
93+
94+
if ($bozjanString) {
95+
[$current, $max] = explode('/', $bozjanString);
96+
$current = filter_var(trim(str_ireplace('-', null, $current)) ?: 0, FILTER_SANITIZE_NUMBER_INT);
9497

95-
$bozjan->Level = (int)$node->find('.character__job__level')->text();
96-
$bozjan->Mettle = $current;
98+
$bozjan->Level = (int)$node->find('.character__job__level')->text();
99+
$bozjan->Mettle = $current;
100+
}
97101
}
98102

99103
//
@@ -102,9 +106,9 @@ public function handle(string $html)
102106
$elemental = new ClassJobEureka('Elemental Level');
103107
$node = $this->dom->find('.character__job__list')[$elementalIndex];
104108

105-
$currentmax = explode('/', $node->find('.character__job__exp')->text());
106-
$current = $currentmax[0] ?? null;
107-
$max = $currentmax[1] ?? null;
109+
$eurekaString = explode('/', $node->find('.character__job__exp')->text());
110+
$current = $eurekaString[0] ?? null;
111+
$max = $eurekaString[1] ?? null;
108112

109113
$current = filter_var(trim(str_ireplace('-', null, $current)) ?: 0, FILTER_SANITIZE_NUMBER_INT);
110114
$max = filter_var(trim(str_ireplace('-', null, $max)) ?: 0, FILTER_SANITIZE_NUMBER_INT);

0 commit comments

Comments
 (0)