From 1043a13f193d27e964ecdd35c0abbd12da68fdad Mon Sep 17 00:00:00 2001 From: Austin White Date: Wed, 29 Jan 2025 16:48:45 -0800 Subject: [PATCH] Updated the frontend function to pass the param. --- resources/js/render-exception.js | 9 ++++++--- .../Controllers/VisualExceptionControllerTest.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/resources/js/render-exception.js b/resources/js/render-exception.js index 066d80c..ec5cce5 100644 --- a/resources/js/render-exception.js +++ b/resources/js/render-exception.js @@ -2,10 +2,11 @@ // Thanks to Caleb Porzio and Jonathan Reinink // Reference: https://github.com/livewire/livewire/blob/1.x/js/connection/drivers/http.js export default { - retrieveLastError() { + retrieveLastError(clear = true) { + const url = `/api/visual-exceptions/latest?clear=${clear ? 'true' : 'false'}`; // Adjust this to the url that is defined in your config - fetch('/api/visual-exceptions/latest', { + fetch(url, { method: 'GET', // This enables "cookies". credentials: 'same-origin', @@ -14,7 +15,9 @@ export default { }, }).then(response => { response.text().then(content => { - this.showHtmlModal(content); + if (content) { + this.showHtmlModal(content); + } }); }); }, diff --git a/tests/Feature/Http/Controllers/VisualExceptionControllerTest.php b/tests/Feature/Http/Controllers/VisualExceptionControllerTest.php index 989cd2a..9ad5846 100644 --- a/tests/Feature/Http/Controllers/VisualExceptionControllerTest.php +++ b/tests/Feature/Http/Controllers/VisualExceptionControllerTest.php @@ -42,4 +42,18 @@ public function test_it_can_delete_the_exception_file_after_returning_it_with_cl Storage::assertMissing(config('visual-exceptions.storage')); } + + public function test_it_will_not_delete_the_exception_file_after_returning_it_without_clear_query_param() + { + Storage::fake('local'); + + Config::set('visual-exceptions.clear_on_retrieve', 'upon-request'); + + Storage::put(config('visual-exceptions.storage'), 'Test Exception Response'); + + $this->get('api/visual-exceptions/latest')->assertSuccessful()->assertSee('Test Exception Response'); + $this->get('api/visual-exceptions/latest?clear=false')->assertSuccessful()->assertSee('Test Exception Response'); + + Storage::assertExists(config('visual-exceptions.storage')); + } }