Return an array from an Exception

@param Exception $e

@return array
961593
static function asArray(Exception $e)
    {
        return [
            'exception'   => get_class($e),
            'code'        => $e->getCode(),
            'message'     => $e->getMessage(),
            'file'        => $e->getFile(),
            'line'        => $e->getLine(),
            'hash'        => self::hash($e),
            'status_code' => self::statusCode($e)
        ];
    }
429358
public function logException(\Exception $e)
    {
        $error = $e->getMessage() . $e->getTraceAsString();
        return $this->logEmergency($error);
    }
397084
protected function convertExceptionToResponse(Exception $e)
    {
        $e = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler(config('app.debug'));

        $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));

        return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders());
    }
304231
protected function provideGeneralErrorResponse(\Exception $e): Response
    {
        $responder = $this->provideResponder();
        return $responder->error([
            'Message' => $e->getMessage(),
            'File' => $e->getFile(),
            'Line' => $e->getLine(),
        ]);
    }
850982
private function formatException(\Exception $exception)
    {
        $result = [
            'message' => $exception->getMessage(),
            'type'      => get_class($exception),
            'code'      => $exception->getCode(),
            'trace' => [
                [
                    'file' => $exception->getFile() ?: 'unknown',
                    'line' => $exception->getLine() ?: 'unknown',
                ]
            ]
        ];

        foreach ($exception->getTrace() as $frame) {
            $result['trace'][] = $this->formatStackFrame($frame);
        }

        if ($previous = $exception->getPrevious()) {
            $result['previous'] = $this->formatException($previous);
        }

        return $result;
    }
1158161
protected function prepareJsonResponse(Exception $e)
    {
        return new JsonResponse(
            $this->convertExceptionToArray($e),
            ($e->getCode() <= 0 || ! is_numeric($e->getCode())) ? 500 : $e->getCode()
        );
    }
215871
protected function convertExceptionToResponse(Exception $e)
    {
        return SymfonyResponse::create(
            $this->renderExceptionContent($e),
            $this->isHttpException($e) ? $e->getStatusCode() : 500,
            $this->isHttpException($e) ? $e->getHeaders() : []
        );
    }
960364
protected function generateExceptionResponse(Exception $e){

        $e = FlattenException::create($e);
        $content = $this->decoreate($this->exceptionHandler->getContent($e), $this->exceptionHandler->getStylesheet($e), 'utf-8');

        return response($content, 500);
    }
347904
protected function convertExceptionToResponse(Exception $e)
    {
        $headers = $this->isHttpException($e) ? $e->getHeaders() : [];
        $statusCode = $this->isHttpException($e) ? $e->getStatusCode() : 500;

        try {
            $content = config('app.debug') && class_exists(Whoops::class)
                ? $this->renderExceptionWithWhoops($e)
                : $this->renderExceptionWithSymfony($e, config('app.debug'));
        } catch (Exception $e) {
            $content = $content ?? $this->renderExceptionWithSymfony($e, config('app.debug'));
        }

        return SymfonyResponse::create(
            $content,
            $statusCode,
            $headers
        );
    }
589842
protected function getCode(\Exception $exception)
    {
        return $exception instanceof \ErrorException ?
            $this->getHumanErrorCode($exception->getSeverity()) :
            $exception->getCode()
        ;
    }
260710
public static function exceptionToArray($exception, $includePrevious = false)
    {
        $array = [
            'message' => $exception->getMessage(),
            'code' => $exception->getCode(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'trace' => $exception->getTraceAsString(),
        ];

        if ($includePrevious) {
            $array['previous'] = self::exceptionToArray($exception->getPrevious(), true);
        }

        return $array;
    }
539612
protected function _get(\Throwable $e)
	{
		$path_to_root = $_SERVER['DOCUMENT_ROOT'];

		$rows = array();
		
		// first row : current script with error line
		$rows[] = [
				// file		
				str_replace($path_to_root . '/', '', $e->getFile()),
			
				// line
				$e->getLine(),
			
				// function
				"throw new " . get_class($e),
			
				// function parameters
				""
			];
		

		
		// for each call stack element
		foreach ( $e->getTrace() as $trace )
		{
			$rows[] = [
					
					// file
					str_replace($path_to_root . '/', '', $trace['file']),
				
					// line
					$trace['line'],
				
					// function
					$trace['class'] ? ($trace['class'] . '::' . $trace['function']) : $trace['function'],
				
					// args
					print_r($trace['args'], true)
				];
		}
		
		
		return $rows;
	}
103517
protected function getTransformed( Exception $exception )
	{
		foreach ( $this->make( array_get( $this->getConfig(), 'transformers', [] ) ) as $transformer )
		{
			var_dump( $transformer );
			$exception = $transformer->transform( $exception );
		}

		return $exception;
	}
1332229
public function exception(\Exception $e)
    {
        $fields = [];

        $addToField = function($name, $value, $short = false) use (&$fields) {
            if (!empty($value)) {
                $fields[] = [
                    'title' => $name,
                    'value' => $value,
                    'short' => $short,
                ];
            }
        };

        $addToField('Environment', app()->environment(), true);
        $addToField('Exception', get_class($e), true);
        $addToField(
            'Http code',
            $e instanceof \Symfony\Component\HttpKernel\Exception\HttpException ? $e->getStatusCode() : 500,
            true
        );
        $addToField('Code', $e->getCode(), true);
        $addToField('File', $e->getFile(), true);
        $addToField('Line', $e->getLine(), true);
        $addToField('Request url', request()->url(), true);
        $addToField('Request method', request()->method(), true);
        $addToField('Request param', json_encode(request()->all()), true);

        $message    = ':bug: Error Occurs on '.app()->environment();
        $type       = 'serious-alert';
        $pretext    = 'Error Occurs on '.app()->environment();
        $attachment = [
            'color'    => 'danger',
            'title'    => $e->getMessage(),
            'fallback' => !empty($e->getMessage()) ? $e->getMessage() : get_class($e),
            'pretext'  => $pretext,
            'fields'   => $fields,
            'text'     => $e->getTraceAsString(),
        ];

        // notify to slack
        $this->post($message, $type, $attachment);
    }
216748
private function linearize(Throwable $e): array
    {
        $previous = $e->getPrevious();

        if (is_null($previous)) return [$e];

        return array_merge($this->linearize($previous), [$e]);
    }
983179
public function formatExceptionData(GeneratedError $e)
    {
        $filePath = $e->getFile();
        if ($filePath && file_exists($filePath)) {
            $lines = file($filePath);
            $start = $e->getLine() - 4;
            $lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
        } else {
            $lines = array("Cannot open the file ($filePath) in which the exception occurred ");
        }

        return array(
//            'type' => get_class($e),
            'type' => '',
            'message' => $e->getMessage(),
            'code' => $e->getCode(),
            'file' => $filePath,
            'line' => $e->getLine(),
            'surrounding_lines' => $lines
        );
    }
348722
protected function normalizeException(\Exception $e)
    {
        $data = array(
            'class' => get_class($e),
            'message' => $e->getMessage(),
            'code' => $e->getCode(),
            'file' => $e->getFile().':'.$e->getLine(),
        );

        $trace = $e->getTrace();
        foreach ($trace as $frame) {
            if (isset($frame['file'])) {
                $data['trace'][] = $frame['file'].':'.$frame['line'];
            } else {
                // We should again normalize the frames, because it might contain invalid items
                $data['trace'][] = $this->toJson($this->normalize($frame, array()), true);
            }
        }

        if ($previous = $e->getPrevious()) {
            $data['previous'] = $this->normalizeException($previous);
        }

        return $this->toJson($data);
    }