mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
better upload error handling
This commit is contained in:
parent
9b1c5e83ff
commit
af6be81db6
3 changed files with 28 additions and 8 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace Demostf\API\Demo;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
|
||||
/**
|
||||
* Wrapper around demo.js parser
|
||||
|
|
@ -18,10 +19,22 @@ class RawParser {
|
|||
}
|
||||
|
||||
public function parse(string $path): ?array {
|
||||
$client = new Client();
|
||||
$response = $client->post($this->parserUrl, [
|
||||
'body' => fopen($path, 'r')
|
||||
]);
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->post($this->parserUrl, [
|
||||
'body' => fopen($path, 'r')
|
||||
]);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
if (is_null($result)) {
|
||||
throw new \Exception('Failed to parse demo, unexpected result from parser');
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
} catch (GuzzleException $e) {
|
||||
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
|
||||
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
|
||||
}
|
||||
throw new \Exception('Failed to parse demo, ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue