Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
106a31a8
Commit
106a31a8
authored
Jul 11, 2018
by
王召彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
21b63068
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
51 deletions
+0
-51
src/Common/Exception/BaseExceptionHandler.php
+0
-51
No files found.
src/Common/Exception/BaseExceptionHandler.php
deleted
100644 → 0
View file @
21b63068
<?php
namespace
Hdll\Services\Common\Exception
;
use
Swoft\App
;
use
Swoft\Bean\Annotation\ExceptionHandler
;
use
Swoft\Bean\Annotation\Handler
;
use
Swoft\Exception\RuntimeException
;
use
Exception
;
use
Swoft\Http\Message\Server\Request
;
use
Swoft\Http\Message\Server\Response
;
use
Swoft\Exception\ValidatorException
;
use
Swoft\Http\Server\Exception\BadRequestException
;
use
Swoft\Http\Server\Exception\RouteNotFoundException
;
class
BaseExceptionHandler
{
/**
* @Handler(Exception::class)
*
* @param Response $response
* @param \Throwable $throwable
*
* @return Response
*/
public
function
handlerException
(
Response
$response
,
\Throwable
$throwable
)
{
$file
=
$throwable
->
getFile
();
$line
=
$throwable
->
getLine
();
$exception
=
$throwable
->
getMessage
();
$code
=
500
;
$error_code
=
0
;
if
(
$throwable
instanceof
ValidatorException
)
{
$code
=
400
;
}
else
if
(
$throwable
instanceof
BadRequestException
)
{
$code
=
400
;
}
else
if
(
$throwable
instanceof
RouteNotFoundException
)
{
$code
=
404
;
}
else
if
(
\method_exists
(
$throwable
,
'getErrcode'
))
{
$code
=
$throwable
->
getCode
();
$error_code
=
$throwable
->
getErrcode
();
}
// $data = ['msg' => $exception, 'file' => $file, 'line' => $line, 'code' => $code, 'error_code'=>$error_code];
// App::error(json_encode($data));
$data
=
[
'error_code'
=>
$error_code
,
'msg'
=>
$exception
,
'data'
=>
null
];
return
$response
->
json
(
$data
)
->
withStatus
(
$code
);
}
}
\ No newline at end of file
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