From ce50af8d9f2cc7c28a265c7a7e4f20e612204da7 Mon Sep 17 00:00:00 2001 From: tsingsun Date: Tue, 19 Dec 2017 16:01:30 +0800 Subject: [PATCH] fix graphql error formater catch the exception throw in app not correct --- src/ErrorFormatter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ErrorFormatter.php b/src/ErrorFormatter.php index 8d5c3b2..fcef164 100644 --- a/src/ErrorFormatter.php +++ b/src/ErrorFormatter.php @@ -6,6 +6,7 @@ use GraphQL\Error\Error; use GraphQL\FormattedError; use yii\graphql\exceptions\ValidatorException; +use yii\web\HttpException; /** * Class ErrorFormatter @@ -21,6 +22,11 @@ public static function formatError(Error $e) if ($previous instanceof ValidatorException) { return $previous->formatErrors; } + if ($previous instanceof HttpException) { + return ['code' => $previous->statusCode, 'message' => $previous->getMessage()]; + } else { + return ['code' => $previous->getCode(), 'message' => $previous->getMessage()]; + } } else { Yii::error($e->getMessage(), get_class($e)); }