Skip to content

Commit

Permalink
Merge pull request #297 from glensc/token-status-code
Browse files Browse the repository at this point in the history
Run/import: Add http status code on errors
  • Loading branch information
glensc authored Aug 21, 2020
2 parents 46e4e8d + 42449da commit 98a7a21
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Xhgui/Controller/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public function import()
try {
$this->runImport($request);
$result = ['ok' => true, 'size' => $request->getContentLength()];
} catch (InvalidArgumentException $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
$response->setStatus(401);
} catch (Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
$response->setStatus(500);
}

$response['Content-Type'] = 'application/json';
Expand All @@ -40,7 +44,7 @@ private function runImport(Request $request)
{
if ($this->token) {
if ($this->token !== $request->get('token')) {
throw new RuntimeException('Token validation failed');
throw new InvalidArgumentException('Token validation failed');
}
}

Expand Down

0 comments on commit 98a7a21

Please sign in to comment.