Error improvements

This commit is contained in:
Chris Kankiewicz
2020-02-17 23:30:17 -07:00
parent 991a843cdb
commit 81dd9cd947
3 changed files with 18 additions and 7 deletions

View File

@@ -52,8 +52,7 @@ class DirectoryHandler
$files = $this->finder->in($path)->depth(0);
} catch (DirectoryNotFoundException $exception) {
return $this->view->render($response->withStatus(404), 'error.twig', [
'code' => 404,
'message' => 'Not Found',
'message' => 'Directory does not exist'
]);
}

View File

@@ -41,10 +41,7 @@ class SearchHandler
$search = $request->getQueryParams()['search'];
if (empty($search)) {
return $this->view->render($response->withStatus(422), 'error.twig', [
'code' => 422,
'message' => 'Unprocessable Entity',
]);
return $this->error($response);
}
$files = $this->finder->in('.')->name(
@@ -54,6 +51,21 @@ class SearchHandler
return $this->view->render($response, 'index.twig', [
'files' => $files,
'search' => $search,
'title' => $search,
]);
}
/**
* Return an error response.
*
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return \Psr\Http\Message\ResponseInterface
*/
protected function error(ResponseInterface $response): ResponseInterface
{
return $this->view->render($response, 'error.twig', [
'message' => 'No results found'
]);
}
}

View File

@@ -6,7 +6,7 @@
<div id="content" class="flex-grow container flex justify-center items-center mx-auto px-4">
<p class="font-thin text-4xl text-gray-600">
{{ code }} &bull; {{ message }}
{{ message | default('An unexpected error occured') }}
</p>
</div>