如果输入的网址错误,在生产模式下,返回的信息是“服务器错误”。我觉得可以在控制结构中增加HttpException的异常处理,返回“请求的地址不存在”。代码如下:
if ($e instanceof BaseException) {
$this->code = $e->code;
$this->errorCode = $e->errorCode;
$this->msg = $e->msg;
} elseif ($e instanceof HttpException) {
$this->code = 500;
$this->errorCode = 999;
$this->msg = '请求的地址不存在';
} else {
if (config('app_debug')) {
return parent::render($e);
} else {
$this->code = 500;
$this->errorCode = 999;
$this->msg = '服务器错误~!';
$this->recordErrorLog($e);
}
}----------------------------------------------------------------------------------------------------------
更新:
除了输入的网址错误,还有可能是请求的方式错误,两者都属于HttpException异常。如果能区分两者最好,如果区分不了,可以提示“请求的地址不存在或请求的方式错误”。