Добавлен кастомный ErrorHandler для форматирования ошибок authserver'а в соответствии с ожиданиями лаунчера

This commit is contained in:
ErickSkrauch 2016-08-31 13:32:14 +03:00
parent 9c658f5bd9
commit 66e266692c
3 changed files with 33 additions and 0 deletions

View 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);
}
}

View File

@ -47,6 +47,9 @@ return [
'class' => \common\components\oauth\Component::class, 'class' => \common\components\oauth\Component::class,
'grantTypes' => ['authorization_code'], 'grantTypes' => ['authorization_code'],
], ],
'errorHandler' => [
'class' => \api\components\ErrorHandler::class,
],
], ],
'modules' => [ 'modules' => [
'authserver' => [ 'authserver' => [

View File

@ -1,8 +1,19 @@
<?php <?php
namespace api\modules\authserver\exceptions; namespace api\modules\authserver\exceptions;
use ReflectionClass;
use yii\web\HttpException; use yii\web\HttpException;
class AuthserverException extends 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();
}
} }