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