mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-26 07:15:30 +02:00
Error improvements
This commit is contained in:
@@ -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'
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -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'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -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 }} • {{ message }}
|
||||
{{ message | default('An unexpected error occured') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user