diff --git a/code/app/home/HomeExceptionHandle.php b/code/app/home/HomeExceptionHandle.php
new file mode 100644
index 0000000..f6fdc77
--- /dev/null
+++ b/code/app/home/HomeExceptionHandle.php
@@ -0,0 +1,66 @@
+getStatusCode() == 404) {
+ return view('../public/error', [
+ 'strErrMsg' => $e->getMessage(),
+ 'strErrCode' => $e->getStatusCode()
+ ])->code(404);
+ }
+
+ // 其他错误交给系统处理
+ return parent::render($request, $e);
+ }
+}
diff --git a/code/app/home/provider.php b/code/app/home/provider.php
new file mode 100644
index 0000000..7b7244c
--- /dev/null
+++ b/code/app/home/provider.php
@@ -0,0 +1,9 @@
+ HomeExceptionHandle::class,
+];
diff --git a/code/app/home/view/public/error.html b/code/app/home/view/public/error.html
new file mode 100644
index 0000000..8583b12
--- /dev/null
+++ b/code/app/home/view/public/error.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+ 404 - 页面未找到
+
+
+
+
+
+
{$strErrCode}
+
{$strErrMsg}
+
5 秒后将自动返回上一页。
+
倒计时:5 秒
+
或者 点击这里返回首页。
+
+
+
diff --git a/code/app/services/ChapterService.php b/code/app/services/ChapterService.php
index b104d07..8cc418d 100644
--- a/code/app/services/ChapterService.php
+++ b/code/app/services/ChapterService.php
@@ -6,6 +6,7 @@ use app\model\ChapterModel;
use app\model\ConverterMovel;
use app\model\NovelModel;
use template\page\CusteomPage02;
+use think\exception\HttpException;
use think\facade\View;
class ChapterService
@@ -223,6 +224,10 @@ class ChapterService
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
+ if (empty($arrNovel)) {
+ throw new HttpException(404, '小说不存在');
+ }
+
$ChapterModel = ChapterModel::getInstance();
if ($intCSortNum === NULL && $intCPage === NULL) {
// 最新章节
@@ -233,6 +238,12 @@ class ChapterService
$arrChapter = $ChapterModel->findOne($arrFilter);
}
+
+ if (empty($arrChapter)) {
+ throw new HttpException(404, '章节不存在');
+ }
+
+
$strChapterDescription = '';
// 上一章节和下一章节
diff --git a/code/app/services/NovelService.php b/code/app/services/NovelService.php
index c9e6794..3742df6 100644
--- a/code/app/services/NovelService.php
+++ b/code/app/services/NovelService.php
@@ -9,6 +9,7 @@ use app\model\DomainModel;
use app\model\NovelClicksModel;
use app\model\NovelModel;
use template\page\CusteomPage02;
+use think\exception\HttpException;
class NovelService
{
@@ -74,7 +75,7 @@ class NovelService
* @param integer $intNForgeId
* @return string
*/
- public function getForgeNovelInfoUrl(int $intNId,string $strPinYin, int $intNForgeId): string
+ public function getForgeNovelInfoUrl(int $intNId, string $strPinYin, int $intNForgeId): string
{
$strKey = 'KAN_NOVEL_INFO_URL';
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
@@ -164,7 +165,7 @@ class NovelService
*/
public function getNovelRankUrl(string|NULL $strGender, string|NULL $strCategory, string|NULL $strStatus, string|NULL $strOrder, int|NULL $intPage): string
{
-
+
$strKey = 'RANK_LIST_URL';
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'strGender' => !empty($strGender) ? $strGender : '',
@@ -639,6 +640,10 @@ class NovelService
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
+ if (empty($arrNovel)) {
+ throw new HttpException(404, '小说不存在');
+ }
+
if ($intNForgeId > 0) {
foreach ($arrNovel['n_forge_novel'] as $arrForgeNovel) {
if ($arrForgeNovel['n_forge_id'] == $intNForgeId) {