mirror of
https://github.com/elyby/accounts.git
synced 2024-11-09 23:12:20 +05:30
Добавлен кастомный ErrorHandler для форматирования ошибок authserver'а в соответствии с ожиданиями лаунчера
This commit is contained in:
parent
9c658f5bd9
commit
66e266692c
19
api/components/ErrorHandler.php
Normal file
19
api/components/ErrorHandler.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace api\components;
|
||||
|
||||
use api\modules\authserver\exceptions\AuthserverException;
|
||||
|
||||
class ErrorHandler extends \yii\web\ErrorHandler {
|
||||
|
||||
public function convertExceptionToArray($exception) {
|
||||
if ($exception instanceof AuthserverException) {
|
||||
return [
|
||||
'error' => $this->getExceptionName($exception),
|
||||
'errorMessage' => $exception->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return parent::convertExceptionToArray($exception);
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,9 @@ return [
|
||||
'class' => \common\components\oauth\Component::class,
|
||||
'grantTypes' => ['authorization_code'],
|
||||
],
|
||||
'errorHandler' => [
|
||||
'class' => \api\components\ErrorHandler::class,
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'authserver' => [
|
||||
|
@ -1,8 +1,19 @@
|
||||
<?php
|
||||
namespace api\modules\authserver\exceptions;
|
||||
|
||||
use ReflectionClass;
|
||||
use yii\web\HttpException;
|
||||
|
||||
class AuthserverException extends HttpException {
|
||||
|
||||
/**
|
||||
* Рефлексия быстрее, как ни странно:
|
||||
* @url https://coderwall.com/p/cpxxxw/php-get-class-name-without-namespace#comment_19313
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return (new ReflectionClass($this))->getShortName();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user