public static function toJson($e, bool $getTrace = true, string $catcher = null): string
    {
        if (!$getTrace) {
            return \json_encode(['msg' => "Error: {$e->getMessage()}"]);
        }

        $map = [
            'code' => $e->getCode() ?: 500,
            'msg'  => sprintf(
                '%s(%d): %s, File: %s(Line %d)',
                \get_class($e),
                $e->getCode(),
                $e->getMessage(),
                $e->getFile(),
                $e->getLine()
            ),
            'data' => $e->getTrace()
        ];

        if ($catcher) {
            $map['catcher'] = $catcher;
        }

        if ($getTrace) {
            $map['trace'] = $e->getTrace();
        }

        return \json_encode($map);
    }
public static function toJson($e, bool $getTrace = true, string $catcher = null): string
    {
        if (!$getTrace) {
            return \json_encode(['msg' => "Error: {$e->getMessage()}"]);
        }

        $map = [
            'code' => $e->getCode() ?: 500,
            'msg'  => sprintf(
                '%s(%d): %s, File: %s(Line %d)',
                \get_class($e),
                $e->getCode(),
                $e->getMessage(),
                $e->getFile(),
                $e->getLine()
            ),
            'data' => $e->getTrace()
        ];

        if ($catcher) {
            $map['catcher'] = $catcher;
        }

        if ($getTrace) {
            $map['trace'] = $e->getTrace();
        }

        return \json_encode($map);
    }
public static function toJson ( $ e , bool $ getTrace = true , string $ catcher = null ) : string { if ( ! $ getTrace ) { return \ json_encode ( [ 'msg' => "Error: {$e->getMessage()}" ] ) ; } $ map = [ 'code' => $ e -> getCode ( ) ? : 500 , 'msg' => sprintf ( '%s(%d): %s, File: %s(Line %d)' , \ get_class ( $ e ) , $ e -> getCode ( ) , $ e -> getMessage ( ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) , 'data' => $ e -> getTrace ( ) ] ; if ( $ catcher ) { $ map [ 'catcher' ] = $ catcher ; } if ( $ getTrace ) { $ map [ 'trace' ] = $ e -> getTrace ( ) ; } return \ json_encode ( $ map ) ; }
Converts an exception into a json string.
@param \Exception|\Throwable $e the exception being converted
@param bool                  $getTrace
@param null|string           $catcher
@return string the string representation of the exception.
Converts an exception into a json string .