Using Redirect Args to Display Errors

if ($error) {
    add_filter('redirect_post_location', function( $location ) use ( $error ) {
        return add_query_arg( 'my-plugin-error', $error->get_error_code(), $location );
    });
}
if ( array_key_exists( 'my-plugin-error', $_GET) ) { ?>