From 8ca6784eec8d8f1e4a9c4f6875704f09aae1103a Mon Sep 17 00:00:00 2001
From: Pitu <7425261+Pitu@users.noreply.github.com>
Date: Tue, 18 Sep 2018 03:52:49 -0300
Subject: Better error handling on invalid links

---
 src/site/views/PublicAlbum.vue | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

(limited to 'src/site/views/PublicAlbum.vue')

diff --git a/src/site/views/PublicAlbum.vue b/src/site/views/PublicAlbum.vue
index e156698..f242957 100644
--- a/src/site/views/PublicAlbum.vue
+++ b/src/site/views/PublicAlbum.vue
@@ -19,7 +19,7 @@
 
 <template>
 	<section class="hero is-fullheight">
-		<template v-if="files.length">
+		<template v-if="files && files.length">
 			<div class="hero-body align-top">
 				<div class="container">
 					<h1 class="title">{{ name }}</h1>
@@ -67,6 +67,23 @@ export default {
 				downloadLink
 			};
 		} catch (error) {
+			return {
+				name: null,
+				downloadEnabled: false,
+				files: [],
+				downloadLink: null,
+				error: error.response.status
+			};
+			/*
+			if (error.response.status === 404) {
+
+				setTimeout(() => this.$router.push('/404'), 3000);
+			} else {
+				console.error(error);
+			}
+			return {};
+			*/
+			/*
 			console.error(error);
 			return {
 				name: null,
@@ -74,6 +91,7 @@ export default {
 				files: [],
 				downloadLink: null
 			};
+			*/
 		}
 	},
 	data() {
@@ -99,17 +117,20 @@ export default {
 		};
 	},
 	mounted() {
+		if (this.error) {
+			if (this.error === 404) {
+				this.$toast.open('Album not found', true, 3000);
+				setTimeout(() => this.$router.push('/404'), 3000);
+				return;
+			} else {
+				this.$toast.open(`Error code ${this.error}`, true, 3000);
+			}
+		}
 		this.$ga.page({
 			page: `/a/${this.$route.params.identifier}`,
 			title: `Album | ${this.name}`,
 			location: window.location.href
 		});
-	},
-	methods: {
-		async downloadAlbum() {
-			const response = await axios.get(`${config.baseURL}/album/${this.$route.params.identifier}/zip`);
-			console.log(response.data);
-		}
 	}
 };
 </script>
-- 
cgit v1.2.3

