Show custom 404 pages for missing anime and characters
This commit is contained in:
parent
f3df8f1588
commit
f7119a5b0f
@ -1,4 +1,4 @@
|
||||
<main>
|
||||
<h1>404</h1>
|
||||
<h2>Page Not Found</h2>
|
||||
<h2><?= $message ?></h2>
|
||||
</main>
|
||||
|
@ -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;
|
||||
|
@ -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 · Anime · " .
|
||||
'Anime not found',
|
||||
'Anime Not Found'
|
||||
);
|
||||
}
|
||||
|
||||
foreach($data['included'] as $included)
|
||||
{
|
||||
if ($included['type'] === 'characters')
|
||||
|
@ -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 · Characters · " .
|
||||
'Character not found',
|
||||
'Character Not Found'
|
||||
);
|
||||
}
|
||||
|
||||
// $this->outputJSON($data);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user