Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
吴磊(PHP)
/
admin-skeleton
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 18726a65
authored
Nov 20, 2025
by
wulei@ldy.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
1 parent
d9fdb78d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
app/Exceptions/Handler.php
app/Exceptions/Handler.php
View file @
18726a6
...
...
@@ -10,8 +10,10 @@ use Illuminate\Database\QueryException;
use
Illuminate\Foundation\Exceptions\Handler
as
ExceptionHandler
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Response
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Validation\ValidationException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\Routing\Exception\RouteNotFoundException
;
use
Throwable
;
class
Handler
extends
ExceptionHandler
...
...
@@ -45,11 +47,11 @@ class Handler extends ExceptionHandler
{
$this
->
renderable
(
function
(
Throwable
$e
,
Request
$request
)
{
if
(
strstr
(
$request
->
getRequestUri
(),
'/api'
)
||
$request
->
expectsJson
())
{
if
(
$e
instanceof
NotFoundHttpException
)
{
if
(
$e
instanceof
NotFoundHttpException
||
$e
instanceof
RouteNotFoundException
)
{
if
(
$e
->
getPrevious
()
instanceof
ModelNotFoundException
)
{
return
ApiResponse
::
error
(
Response
::
HTTP_NOT_FOUND
,
'
记录
找不到了'
);
return
ApiResponse
::
error
(
Response
::
HTTP_NOT_FOUND
,
'
数据
找不到了'
);
}
return
ApiResponse
::
error
(
Response
::
HTTP_NOT_FOUND
,
'未知接口'
);
return
ApiResponse
::
error
(
Response
::
HTTP_NOT_FOUND
,
$e
->
getMessage
()
);
}
elseif
(
$e
instanceof
AuthenticationException
)
{
return
ApiResponse
::
error
(
Response
::
HTTP_UNAUTHORIZED
,
'未授权的访问'
);
}
elseif
(
$e
instanceof
AuthorizationException
)
{
...
...
@@ -57,10 +59,21 @@ class Handler extends ExceptionHandler
}
elseif
(
$e
instanceof
ValidationException
)
{
return
ApiResponse
::
error
(
Response
::
HTTP_UNPROCESSABLE_ENTITY
,
'数据验证失败'
,
$e
->
errors
());
}
elseif
(
$e
instanceof
QueryException
)
{
return
ApiResponse
::
error
(
Response
::
HTTP_INTERNAL_SERVER_ERROR
,
'数据错误'
);
}
else
{
return
ApiResponse
::
error
();
return
ApiResponse
::
error
(
Response
::
HTTP_INTERNAL_SERVER_ERROR
,
'数据查询异常'
,
config
(
'app.env'
)
<>
'production'
?
[
'sql'
=>
$e
->
getSql
(),
'binds'
=>
$e
->
getBindings
(),
'message'
=>
$e
->
getMessage
(),
]
:
null
);
}
Log
::
error
(
$e
->
getMessage
(),
[
'path'
=>
request
()
->
path
(),
'query'
=>
request
()
->
query
(),
'class'
=>
get_class
(
$e
),
'file'
=>
$e
->
getFile
()
.
':'
.
$e
->
getLine
()
]);
return
ApiResponse
::
error
();
}
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment