From dd2b297cc5b066195b56c482501b6510fce5d2e0 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 22 Aug 2019 12:12:44 -0400 Subject: [PATCH] Carry headers when rethrowing errors to REST --- app/Exceptions/Converters/GenericException.php | 11 +++++++---- app/Exceptions/Converters/SymfonyException.php | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Exceptions/Converters/GenericException.php b/app/Exceptions/Converters/GenericException.php index ff8b949f..9f028102 100644 --- a/app/Exceptions/Converters/GenericException.php +++ b/app/Exceptions/Converters/GenericException.php @@ -39,13 +39,16 @@ class GenericException extends HttpException */ public function getErrorMetadata(): array { + $metadata = []; + $metadata['error'] = [ + 'original_exception' => get_class($this->exception), + ]; + // Only add trace if in dev if (config('app.env') === 'dev') { - return [ - 'trace' => $this->exception->getTrace()[0], - ]; + $metadata['trace'] = $this->exception->getTrace()[0]; } - return []; + return $metadata; } } diff --git a/app/Exceptions/Converters/SymfonyException.php b/app/Exceptions/Converters/SymfonyException.php index 8887d6df..45e3d10d 100644 --- a/app/Exceptions/Converters/SymfonyException.php +++ b/app/Exceptions/Converters/SymfonyException.php @@ -14,7 +14,9 @@ class SymfonyException extends HttpException $this->exception = $exception; parent::__construct( $exception->getStatusCode(), - $exception->getMessage() + $exception->getMessage(), + null, + $exception->getHeaders() ); } @@ -23,7 +25,7 @@ class SymfonyException extends HttpException */ public function getErrorType(): string { - return 'internal-error'; + return 'http-exception'; } /**