Skip to content

Commit

Permalink
Merge pull request #18 from phper666/v2.0.3
Browse files Browse the repository at this point in the history
1、规范异常http状态码,500状态码改为400
  • Loading branch information
phper666 authored Feb 26, 2020
2 parents 05e91d1 + 0037641 commit fcfedec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ class IndexController extends AbstractController
例如:`$this->jwt->getParserData()`
##### 12、建议
> 目前 `jwt` 抛出的异常目前有两种类型 `Phper666\JwtAuth\Exception\TokenValidException``Phper666\JwtAuth\Exception\JWTException,TokenValidException` 异常为 token 验证失败的异常,会抛出 `401` ,`JWTException` 异常会抛出 `500`,最好你们自己在项目异常重新返回错误信息
> 目前 `jwt` 抛出的异常目前有两种类型 `Phper666\JwtAuth\Exception\TokenValidException``Phper666\JwtAuth\Exception\JWTException,TokenValidException` 异常为 token 验证失败的异常,会抛出 `401` ,`JWTException` 异常会抛出 `400`,最好你们自己在项目异常重新返回错误信息
4 changes: 2 additions & 2 deletions src/Jwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getToken(array $claims, $isInsertSsoBlack = true)
$uniqid = uniqid();
} else { // 单点登录
if (empty($claims[$this->ssoKey])) {
throw new JWTException("There is no {$this->ssoKey} key in the claims", 500);
throw new JWTException("There is no {$this->ssoKey} key in the claims", 400);
}
$uniqid = $claims[$this->ssoKey];
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getToken(array $claims, $isInsertSsoBlack = true)
public function refreshToken()
{
if (!$this->getHeaderToken()) {
throw new JWTException('A token is required', 500);
throw new JWTException('A token is required', 400);
}
$claims = $this->blacklist->add($this->getTokenObj());
unset($claims['iat']);
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/CommonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function verifyToken(Token $token)
{
$alg = $token->getHeader('alg');
if (empty($this->supportedAlgs[$alg])) {
throw new TokenValidException('Algorithm not supported', 500);
throw new TokenValidException('Algorithm not supported', 401);
}
/** @var Signer $signer */
$signer = new $this->supportedAlgs[$alg];
Expand Down Expand Up @@ -210,7 +210,7 @@ public function getHeaderToken()
return $token;
}

throw new JWTException('A token is required', 500);
throw new JWTException('A token is required', 400);
}

/**
Expand Down

0 comments on commit fcfedec

Please sign in to comment.