Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨昕
media-resource
Commits
785b41c2
Commit
785b41c2
authored
Apr 25, 2021
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化异常处理模块
parent
2737d7f8
Pipeline
#14300
passed with stages
in 4 minutes 16 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
Handler.php
app/Exceptions/Handler.php
+7
-5
No files found.
app/Exceptions/Handler.php
View file @
785b41c2
...
@@ -61,18 +61,22 @@ class Handler extends ExceptionHandler
...
@@ -61,18 +61,22 @@ class Handler extends ExceptionHandler
// var_dump($exception->getLine());
// var_dump($exception->getLine());
#
检测当前请求是否是api路由
#
处理api请求404异常
if
(
stripos
(
$path
,
'api/'
)
===
0
if
(
stripos
(
$path
,
'api/'
)
===
0
&&
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
)
)
{
&&
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
)
)
{
return
error
(
'resources not found'
,
\Symfony\Component\HttpFoundation\Response
::
HTTP_NOT_FOUND
);
return
error
(
'resources not found'
,
\Symfony\Component\HttpFoundation\Response
::
HTTP_NOT_FOUND
);
}
}
if
(
(
(
stripos
(
$path
,
'web/'
)
===
0
&&
strrpos
(
$path
,
'.php'
)
!==
false
)
||
(
stripos
(
$path
,
'web/'
)
===
0
&&
strrpos
(
$path
,
'.html'
)
!==
false
)
)
&&
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
)
)
{
#处理web请求404异常
if
(
stripos
(
$path
,
'web/'
)
===
0
&&
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
)
)
{
if
(
view
()
->
exists
(
'errors.404'
))
{
if
(
view
()
->
exists
(
'errors.404'
))
{
return
response
()
->
view
(
'errors.404'
);
return
response
()
->
view
(
'errors.404'
);
}
}
}
}
/**
* Api异常处理模块
*/
if
(
self
::
handlerException
(
$exception
))
{
if
(
self
::
handlerException
(
$exception
))
{
# 获取常量类里面的异常常量
# 获取常量类里面的异常常量
$message
=
json_decode
(
$exception
->
getMessage
(),
true
);
$message
=
json_decode
(
$exception
->
getMessage
(),
true
);
...
@@ -85,15 +89,13 @@ class Handler extends ExceptionHandler
...
@@ -85,15 +89,13 @@ class Handler extends ExceptionHandler
if
(
$exception
->
getMessage
()
==
'Too Many Attempts.'
)
{
if
(
$exception
->
getMessage
()
==
'Too Many Attempts.'
)
{
return
error
(
'请求接口过于频繁'
,
429
);
return
error
(
'请求接口过于频繁'
,
429
);
}
}
}
else
if
(
$exception
instanceof
\RedisException
){
}
else
if
(
$exception
instanceof
\RedisException
){
return
error
(
'redis连接异常'
);
return
error
(
'redis连接异常'
);
}
}
if
(
$request
->
is
(
'api/*'
))
{
if
(
$request
->
is
(
'api/*'
)
)
{
return
error
(
'服务器请求异常:'
.
$exception
->
getMessage
()
.
"异常信息详情:"
.
$exception
->
getTraceAsString
(),
500
);
return
error
(
'服务器请求异常:'
.
$exception
->
getMessage
()
.
"异常信息详情:"
.
$exception
->
getTraceAsString
(),
500
);
}
else
{
}
else
{
if
(
$exception
->
getMessage
()
!=
''
)
{
if
(
$exception
->
getMessage
()
!=
''
)
{
//print_r($exception->getMessage());
//print_r($exception->getMessage());
if
(
$exception
->
getMessage
()
==
403
)
{
if
(
$exception
->
getMessage
()
==
403
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment