Show custom 404 pages for missing anime and characters

This commit is contained in:
Timothy Warren 2017-03-24 09:08:39 -04:00
parent 51c26e6b30
commit cdd3878e55
5 changed files with 37 additions and 7 deletions

View File

@ -1,4 +1,4 @@
<main>
<h1>404</h1>
<h2>Page Not Found</h2>
<h2><?= $message ?></h2>
</main>

View File

@ -196,8 +196,13 @@ class Model {
*/
public function getAnime(string $slug): array
{
// @TODO catch non-existent anime
$baseData = $this->getRawMediaData('anime', $slug);
if (empty($baseData))
{
return [];
}
$transformed = $this->animeTransformer->transform($baseData);
$transformed['included'] = $baseData['included'];
return $transformed;
@ -657,6 +662,12 @@ class Model {
];
$data = $this->getRequest($type, $options);
if (empty($data['data']))
{
return [];
}
$baseData = $data['data'][0]['attributes'];
$baseData['included'] = $data['included'];
return $baseData;

View File

@ -262,7 +262,17 @@ class Anime extends BaseController {
{
$data = $this->model->getAnime($animeId);
$characters = [];
if (empty($data))
{
return $this->notFound(
$this->config->get('whose_list') .
"'s Anime List &middot; Anime &middot; " .
'Anime not found',
'Anime Not Found'
);
}
foreach($data['included'] as $included)
{
if ($included['type'] === 'characters')

View File

@ -26,9 +26,14 @@ class Character extends BaseController {
$data = $model->getCharacter($slug);
if ( ! array_key_exists('data', $data))
if (( ! array_key_exists('data', $data)) || empty($data['data']))
{
return $this->notFound();
return $this->notFound(
$this->config->get('whose_list') .
"'s Anime List &middot; Characters &middot; " .
'Character not found',
'Character Not Found'
);
}
// $this->outputJSON($data);

View File

@ -234,10 +234,14 @@ trait ControllerTrait {
*
* @return void
*/
public function notFound()
public function notFound(
string $title = 'Sorry, page not found',
string $message = 'Page Not Found'
)
{
$this->outputHTML('404', [
'title' => 'Sorry, page not found'
'title' => $title,
'message' => $message,
], NULL, 404);
}