1
0
Fork 0
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:
Robin Appelman 2017-06-02 23:20:44 +02:00
commit af6be81db6
3 changed files with 28 additions and 8 deletions

View file

@ -1,11 +1,11 @@
FROM php:7.1-fpm-alpine FROM php:7.1-fpm-alpine
RUN apk add --no-cache postgresql-dev wget autoconf g++ libc-dev make \ RUN apk add --no-cache postgresql-dev wget autoconf g++ libc-dev make pcre-dev \
&& mkdir -p /app/src \ && mkdir -p /app/src \
&& docker-php-ext-install pdo_pgsql \ && docker-php-ext-install pdo_pgsql \
&& pecl install apcu \ && pecl install apcu \
&& docker-php-ext-enable apcu \ && docker-php-ext-enable apcu \
&& apk del autoconf g++ libc-dev make && apk del autoconf g++ libc-dev make pcre-dev
COPY composer.json /app COPY composer.json /app
COPY src /app/src COPY src /app/src

View file

@ -18,6 +18,13 @@ class UploadController extends BaseController {
$demo = $this->file('demo'); $demo = $this->file('demo');
$demoFile = $demo['tmp_name']; $demoFile = $demo['tmp_name'];
echo $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile); try {
echo $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile);
} catch (\Exception $e) {
\Flight::response()
->status(500)
->write($e->getMessage())
->send();
}
} }
} }

View file

@ -3,6 +3,7 @@
namespace Demostf\API\Demo; namespace Demostf\API\Demo;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/** /**
* Wrapper around demo.js parser * Wrapper around demo.js parser
@ -18,10 +19,22 @@ class RawParser {
} }
public function parse(string $path): ?array { public function parse(string $path): ?array {
$client = new Client(); try {
$response = $client->post($this->parserUrl, [ $client = new Client();
'body' => fopen($path, 'r') $response = $client->post($this->parserUrl, [
]); 'body' => fopen($path, 'r')
return json_decode($response->getBody()->getContents(), true); ]);
$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());
}
} }
} }