From 7cc79c2f19d59044e52e6ccdb5764b4e5b0e2729 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sat, 4 Apr 2020 23:45:12 -0700 Subject: [PATCH] Show error message when file hashing fails --- app/resources/js/components/file-info-modal.vue | 17 ++++++++++++----- app/src/Controllers/FileInfoController.php | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/resources/js/components/file-info-modal.vue b/app/resources/js/components/file-info-modal.vue index ad1e784..3caedf4 100644 --- a/app/resources/js/components/file-info-modal.vue +++ b/app/resources/js/components/file-info-modal.vue @@ -22,7 +22,11 @@
- +

+ {{ error }} +

+ +
@@ -44,6 +48,7 @@ export default { data: function () { return { + error: null, filePath: 'file-info.txt', hashes: { 'md5': '••••••••••••••••••••••••••••••••', @@ -69,14 +74,16 @@ await axios.get('?info=' + filePath).then(function (response) { this.hashes = response.data.hashes; - this.loading = false; - }.bind(this)).catch( - response => this.hide() && console.error(response) - ); + }.bind(this)).catch(function (error) { + this.error = error.response.data.message; + }.bind(this)); + + this.loading = false; }, hide() { this.visible = false; this.loading = true; + this.error = null; } }, mounted() { diff --git a/app/src/Controllers/FileInfoController.php b/app/src/Controllers/FileInfoController.php index f4d4fe1..652f7d7 100644 --- a/app/src/Controllers/FileInfoController.php +++ b/app/src/Controllers/FileInfoController.php @@ -48,10 +48,18 @@ class FileInfoController ); if (! $file->isFile()) { + $response->getBody()->write(json_encode([ + 'message' => $this->translator->trans('error.file_not_found'), + ])); + return $response->withStatus(404, $this->translator->trans('error.file_not_found')); } if ($file->getSize() >= $this->container->get('max_hash_size')) { + $response->getBody()->write(json_encode([ + 'message' => $this->translator->trans('error.file_size_exceeded'), + ])); + return $response->withStatus(500, $this->translator->trans('error.file_size_exceeded')); }
{{ title }}