RRZE-Webteam / rrze-elements-blocks

Sammlung von Gestaltungselementen für WordPress-Websites für den BlockEditor
GNU General Public License v3.0
2 stars 0 forks source link

Als Entwickler möchte ich, dass ausgelöste ErrorBoundaries in der ErrorLog erscheinen #147

Open lukasniebler opened 2 months ago

lukasniebler commented 2 months ago

User Story

Als Entwickler möchte ich, dass ausgelöste ErrorBoundaries in der ErrorLog erscheinen

Grundlegendes Problem

Fehler werden aktuell nur in der Browserkonsole und im ErrorBoundary angezeigt, was Support schwierig machen könnte.

Möglicher Lösungsvorschlag

<?php    
    add_action('enqueue_block_editor_assets', [$this, 'adminBlockEditorAssets']);

    public function adminBlockEditorAssets()
    {
        wp_register_script(
            'my-block-script',
            plugin_dir_url(__FILE__) . 'block-script.js',
            [
                'wp-blocks',
                'wp-element',
                'wp-hooks',
                'jquery'
            ],
            '1.0',
            true
        );
        wp_localize_script(
            'my-block-script',
            'ajaxObject',
            [
                'ajaxUrl' => admin_url('admin-ajax.php')
            ]
        );
        wp_enqueue_script('my-block-script');
    }   
?>
<script>
    // Block Script (extract)
    const { hooks } = wp;
    const { ajaxUrl } = ajaxObject;

    const ErrorCaptureTool = {
        captureError: function(error) {
            // Using console.error() to log the error
            console.error(error);
            // Using jQuery.post() to send the error to the server
            jQuery.post(ajax_url, {
                action: 'rrze_log_editor_error_boundary',
                error: error.message
            });
        }
    };

    // Using React Error Boundary component to catch errors
    hooks.addAction(
        'editor.ErrorBoundary.errorLogged',
        'rrze-log-editor-error-boundary/handle-error',
        ErrorCaptureTool.captureError(error)
    );
</script>

Weiterer Input oder Inspiration von anderen Lösungen

Weiteren Input hier einfügen