From 9a5a83c0f7b8b68ddaac52c63b2eb4a5b70c6fb3 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 14 Aug 2019 13:18:32 +0200 Subject: [PATCH 1/5] Show error when array cache is used --- resources/js/screens/dumps/index.vue | 22 +++++++++++++++++++--- src/Http/Controllers/DumpController.php | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/js/screens/dumps/index.vue b/resources/js/screens/dumps/index.vue index 36ded74d4..ddc037f2a 100644 --- a/resources/js/screens/dumps/index.vue +++ b/resources/js/screens/dumps/index.vue @@ -9,6 +9,7 @@ return { entries: [], ready: false, + error: null, newEntriesTimeout: null, newEntriesTimeoutInSeconds: 2000, recordingStatus: 'enabled' @@ -38,14 +39,21 @@ methods: { loadEntries(){ axios.post(Telescope.basePath + '/telescope-api/dumps').then(response => { + this.error = null; this.entries = response.data.entries; this.recordingStatus = response.data.status; - this.ready = true; - this.newEntriesTimeout = setTimeout(() => { this.loadEntries(); }, this.newEntriesTimeoutInSeconds); + }).catch(error => { + if (error.response && error.response.data.message) { + this.error = error.response.data.message; + } else { + this.error = 'Something went wrong'; + } + }).finally(() => { + this.ready = true; }); } } @@ -76,7 +84,7 @@ -
+
@@ -84,6 +92,14 @@ We didn't find anything - just empty space.
+
+ + + + + Whoops: {{ error }} +
+
diff --git a/src/Http/Controllers/DumpController.php b/src/Http/Controllers/DumpController.php index 4c3b8d861..c6abad5e0 100644 --- a/src/Http/Controllers/DumpController.php +++ b/src/Http/Controllers/DumpController.php @@ -2,7 +2,9 @@ namespace Laravel\Telescope\Http\Controllers; +use Illuminate\Cache\ArrayStore; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Laravel\Telescope\EntryType; use Laravel\Telescope\Watchers\DumpWatcher; use Laravel\Telescope\Contracts\EntriesRepository; @@ -37,6 +39,9 @@ public function __construct(CacheRepository $cache) */ public function index(Request $request, EntriesRepository $storage) { + if ($this->cache->getStore() instanceof ArrayStore) { + abort(400, 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.'); + } $this->cache->put('telescope:dump-watcher', true, now()->addSeconds(4)); return parent::index($request, $storage); From e48f6a10ecde89e123e62ba5ef71eedf9fc0a753 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 14 Aug 2019 13:35:21 +0200 Subject: [PATCH 2/5] Check entries before loading --- resources/js/screens/dumps/index.vue | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/resources/js/screens/dumps/index.vue b/resources/js/screens/dumps/index.vue index ddc037f2a..547cdec90 100644 --- a/resources/js/screens/dumps/index.vue +++ b/resources/js/screens/dumps/index.vue @@ -11,7 +11,7 @@ ready: false, error: null, newEntriesTimeout: null, - newEntriesTimeoutInSeconds: 2000, + newEntriesTimer: 2000, recordingStatus: 'enabled' }; }, @@ -43,9 +43,7 @@ this.entries = response.data.entries; this.recordingStatus = response.data.status; - this.newEntriesTimeout = setTimeout(() => { - this.loadEntries(); - }, this.newEntriesTimeoutInSeconds); + this.checkForNewEntries(); }).catch(error => { if (error.response && error.response.data.message) { this.error = error.response.data.message; @@ -55,7 +53,27 @@ }).finally(() => { this.ready = true; }); - } + }, + + + /** + * Keep checking if there are new entries. + */ + checkForNewEntries(){ + this.newEntriesTimeout = setTimeout(() => { + axios.post(Telescope.basePath + '/telescope-api/dumps?take=1').then(response => { + this.recordingStatus = response.data.status; + + if (response.data.entries.length && !this.entries.length) { + this.loadEntries(); + } else if (response.data.entries.length && _.first(response.data.entries).id !== _.first(this.entries).id) { + this.loadEntries(); + } else { + this.checkForNewEntries(); + } + }) + }, this.newEntriesTimer); + }, } } From 927297144e86d39fdf12d7f05dddd72673b3b190 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 14 Aug 2019 13:40:26 +0200 Subject: [PATCH 3/5] Tweak dump error response --- src/Http/Controllers/DumpController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Http/Controllers/DumpController.php b/src/Http/Controllers/DumpController.php index c6abad5e0..6afbbb5e3 100644 --- a/src/Http/Controllers/DumpController.php +++ b/src/Http/Controllers/DumpController.php @@ -4,7 +4,6 @@ use Illuminate\Cache\ArrayStore; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Cache; use Laravel\Telescope\EntryType; use Laravel\Telescope\Watchers\DumpWatcher; use Laravel\Telescope\Contracts\EntriesRepository; @@ -39,8 +38,10 @@ public function __construct(CacheRepository $cache) */ public function index(Request $request, EntriesRepository $storage) { - if ($this->cache->getStore() instanceof ArrayStore) { - abort(400, 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.'); + if ($this->cache->getStore() instanceof ArrayStore) { + return response()->json([ + 'message' => 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.' + ], 400); } $this->cache->put('telescope:dump-watcher', true, now()->addSeconds(4)); From 37f41f8440b36998cc8d1d3d77f8069caf87a18a Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 14 Aug 2019 13:54:43 +0200 Subject: [PATCH 4/5] CS --- src/Http/Controllers/DumpController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/DumpController.php b/src/Http/Controllers/DumpController.php index 6afbbb5e3..2705e711d 100644 --- a/src/Http/Controllers/DumpController.php +++ b/src/Http/Controllers/DumpController.php @@ -2,8 +2,8 @@ namespace Laravel\Telescope\Http\Controllers; -use Illuminate\Cache\ArrayStore; use Illuminate\Http\Request; +use Illuminate\Cache\ArrayStore; use Laravel\Telescope\EntryType; use Laravel\Telescope\Watchers\DumpWatcher; use Laravel\Telescope\Contracts\EntriesRepository; @@ -40,7 +40,7 @@ public function index(Request $request, EntriesRepository $storage) { if ($this->cache->getStore() instanceof ArrayStore) { return response()->json([ - 'message' => 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.' + 'message' => 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.', ], 400); } $this->cache->put('telescope:dump-watcher', true, now()->addSeconds(4)); From 81b42857af822b224336125abe02d192411c14ff Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 14 Aug 2019 08:13:58 -0500 Subject: [PATCH 5/5] Update DumpController.php --- src/Http/Controllers/DumpController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Http/Controllers/DumpController.php b/src/Http/Controllers/DumpController.php index 2705e711d..d58a573fd 100644 --- a/src/Http/Controllers/DumpController.php +++ b/src/Http/Controllers/DumpController.php @@ -43,6 +43,7 @@ public function index(Request $request, EntriesRepository $storage) 'message' => 'The Array cache driver cannot be used for Dumps. Please use a persistent cache.', ], 400); } + $this->cache->put('telescope:dump-watcher', true, now()->addSeconds(4)); return parent::index($request, $storage);