Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Easy Http SDK
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Back End
Easy Http SDK
Commits
09bd415a
Commit
09bd415a
authored
Feb 20, 2023
by
谢宇轩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(Policy): 修改定义
parent
a83f16ea
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
16 additions
and
6 deletions
+16
-6
Application.php
src/Application.php
+1
-1
ApplicationException.php
src/Exception/ApplicationException.php
+2
-0
GuiltyResultException.php
src/Exception/GuiltyResultException.php
+2
-0
SdkException.php
src/Exception/SdkException.php
+3
-1
TimeOutExcetpion.php
src/Exception/TimeOutExcetpion.php
+3
-1
UnknowResultException.php
src/Exception/UnknowResultException.php
+2
-0
Option.php
src/Option.php
+1
-1
Option.temp
template/Option.temp
+2
-2
No files found.
src/Application.php
View file @
09bd415a
...
...
@@ -221,7 +221,7 @@ class Application implements ClientInterface
if
(
$response
->
getStatusCode
()
!=
304
)
{
try
{
$rpcResult
=
$this
->
option
->
errorH
andlingPolicy
()
->
process
(
$response
);
$rpcResult
=
$this
->
option
->
h
andlingPolicy
()
->
process
(
$response
);
}
catch
(
GuiltyResultException
$exception
)
{
// 没有通过预期判定,转化为 SDK Exception
$this
->
lastRequestContext
[
'error_message'
]
=
$exception
->
getMessage
();
...
...
src/Exception/ApplicationException.php
View file @
09bd415a
...
...
@@ -12,6 +12,8 @@ class ApplicationException extends ConnectException implements SdkExceptionInter
use
QueryPath
;
/**
* 应用异常
*
* @param string $message
* @param SdkRequest|null $request
* @param array<string, mixed> $handlerContext
...
...
src/Exception/GuiltyResultException.php
View file @
09bd415a
...
...
@@ -11,6 +11,8 @@ class GuiltyResultException extends UnexpectedValueException
private
$options
;
/**
* 判断为 API 逻辑错误的异常,会转化为 SDK Exception
*
* @param string $message
* @param array<string, mixed> $options
* @param int $code
...
...
src/Exception/SdkException.php
View file @
09bd415a
...
...
@@ -14,6 +14,8 @@ class SdkException extends BadResponseException implements SdkExceptionInterface
use
QueryPath
;
/**
* SDK 中的逻辑异常
*
* @param string $message
* @param SdkRequest $request
* @param ResponseInterface $response
...
...
@@ -42,4 +44,4 @@ class SdkException extends BadResponseException implements SdkExceptionInterface
{
return
$this
->
getHandlerContext
();
}
}
\ No newline at end of file
}
src/Exception/TimeOutExcetpion.php
View file @
09bd415a
...
...
@@ -15,6 +15,8 @@ class TimeOutExcetpion extends ApplicationException implements SdkExceptionInter
protected
$message
=
"time out."
;
/**
* 请求超时异常
*
* @param SdkRequest $request
* @param Throwable|null $previous
*/
...
...
@@ -25,4 +27,4 @@ class TimeOutExcetpion extends ApplicationException implements SdkExceptionInter
{
parent
::
__construct
(
$this
->
message
,
$request
,
[],
$previous
);
}
}
\ No newline at end of file
}
src/Exception/UnknowResultException.php
View file @
09bd415a
...
...
@@ -11,6 +11,8 @@ class UnknowResultException extends UnexpectedValueException
public
$result
;
/**
* 无法解析API返回的异常,会转化为 Application Exception
*
* @param string $message
* @param string $result
* @param int $code
...
...
src/Option.php
View file @
09bd415a
...
...
@@ -36,7 +36,7 @@ abstract class Option
* 错误处理策略
* @return HandlingPolicyInterface
*/
public
function
errorH
andlingPolicy
()
:
HandlingPolicyInterface
public
function
h
andlingPolicy
()
:
HandlingPolicyInterface
{
return
new
DefaultErrorHandlingPolicy
();
}
...
...
template/Option.temp
View file @
09bd415a
...
...
@@ -41,11 +41,11 @@ class {{ Name }}Option extends Option
}
/**
*
错误
处理策略
*
结果
处理策略
*
* @return HandlingPolicyInterface
*/
public
function
errorH
andlingPolicy
()
:
HandlingPolicyInterface
public
function
h
andlingPolicy
()
:
HandlingPolicyInterface
{
return
new
DefaultErrorHandlingPolicy
();
}
...
...
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