mirror of
				https://github.com/TeamPiped/Piped.git
				synced 2024-08-14 23:57:27 +00:00 
			
		
		
		
	Add error handling for Videos, Channels, and Playlists.
This commit is contained in:
		
							parent
							
								
									33eb5226a2
								
							
						
					
					
						commit
						52fa3546a2
					
				
					 4 changed files with 73 additions and 34 deletions
				
			
		| 
						 | 
					@ -1,8 +1,10 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div v-if="channel">
 | 
					    <ErrorHandler v-if="channel && channel.error" :message="channel.message" :error="channel.error" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <div v-if="channel" v-show="!channel.error">
 | 
				
			||||||
        <h1 class="uk-text-center"><img height="48" width="48" v-bind:src="channel.avatarUrl" />{{ channel.name }}</h1>
 | 
					        <h1 class="uk-text-center"><img height="48" width="48" v-bind:src="channel.avatarUrl" />{{ channel.name }}</h1>
 | 
				
			||||||
        <img v-if="channel.bannerUrl" v-bind:src="channel.bannerUrl" style="width: 100%" loading="lazy" />
 | 
					        <img v-if="channel.bannerUrl" v-bind:src="channel.bannerUrl" style="width: 100%" loading="lazy" />
 | 
				
			||||||
        <p v-html="this.channel.description.replaceAll('\n', '<br>')"></p>
 | 
					        <p v-html="this.channel.description" style="white-space: pre"></p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <hr />
 | 
					        <hr />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +37,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import Constants from "@/Constants.js";
 | 
					import Constants from "@/Constants.js";
 | 
				
			||||||
 | 
					import ErrorHandler from "@/components/ErrorHandler.vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    data() {
 | 
					    data() {
 | 
				
			||||||
| 
						 | 
					@ -63,7 +66,9 @@ export default {
 | 
				
			||||||
        async getChannelData() {
 | 
					        async getChannelData() {
 | 
				
			||||||
            this.fetchChannel()
 | 
					            this.fetchChannel()
 | 
				
			||||||
                .then(data => (this.channel = data))
 | 
					                .then(data => (this.channel = data))
 | 
				
			||||||
                .then(() => (document.title = this.channel.name + " - Piped"));
 | 
					                .then(() => {
 | 
				
			||||||
 | 
					                    if (!this.channel.error) document.title = this.channel.name + " - Piped";
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        handleScroll() {
 | 
					        handleScroll() {
 | 
				
			||||||
            if (this.loading || !this.channel || !this.channel.nextpage) return;
 | 
					            if (this.loading || !this.channel || !this.channel.nextpage) return;
 | 
				
			||||||
| 
						 | 
					@ -84,5 +89,8 @@ export default {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        ErrorHandler,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/components/ErrorHandler.vue
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/components/ErrorHandler.vue
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					    <p>{{ message }}</p>
 | 
				
			||||||
 | 
					    <button uk-toggle="target: #stacktrace" class="uk-button uk-button-small" style="background: #222" type="button">
 | 
				
			||||||
 | 
					        Show More
 | 
				
			||||||
 | 
					    </button>
 | 
				
			||||||
 | 
					    <p id="stacktrace" style="white-space: pre" hidden>{{ error }}</p>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					    props: {
 | 
				
			||||||
 | 
					        error: String,
 | 
				
			||||||
 | 
					        message: String,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div v-if="playlist">
 | 
					    <ErrorHandler v-if="playlist && playlist.error" :message="playlist.message" :error="playlist.error" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <div v-if="playlist" v-show="!playlist.error">
 | 
				
			||||||
        <h1 class="uk-text-center">
 | 
					        <h1 class="uk-text-center">
 | 
				
			||||||
            <img v-bind:src="playlist.avatarUrl" height="48" width="48" loading="lazy" />
 | 
					            <img v-bind:src="playlist.avatarUrl" height="48" width="48" loading="lazy" />
 | 
				
			||||||
            {{ playlist.name }}
 | 
					            {{ playlist.name }}
 | 
				
			||||||
| 
						 | 
					@ -44,6 +46,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import Constants from "@/Constants.js";
 | 
					import Constants from "@/Constants.js";
 | 
				
			||||||
 | 
					import ErrorHandler from "@/components/ErrorHandler.vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    data() {
 | 
					    data() {
 | 
				
			||||||
| 
						 | 
					@ -86,5 +89,8 @@ export default {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    components: {
 | 
				
			||||||
 | 
					        ErrorHandler,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,31 +1,36 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div class="uk-container uk-container-xlarge">
 | 
					    <div class="uk-container uk-container-xlarge">
 | 
				
			||||||
        <Player ref="videoPlayer" :video="video" :sponsors="sponsors" :selectedAutoPlay="selectedAutoPlay" />
 | 
					        <ErrorHandler v-if="video.error" :message="video.message" :error="video.error" />
 | 
				
			||||||
        <h1 class="uk-text-bold">{{ video.title }}</h1>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <img :src="video.uploaderAvatar" loading="lazy" />
 | 
					        <div v-show="!video.error">
 | 
				
			||||||
        <router-link class="uk-text-bold" v-bind:to="video.uploaderUrl || '/'">
 | 
					            <Player ref="videoPlayer" :video="video" :sponsors="sponsors" :selectedAutoPlay="selectedAutoPlay" />
 | 
				
			||||||
            <a>{{ video.uploader }}</a>
 | 
					            <h1 class="uk-text-bold">{{ video.title }}</h1>
 | 
				
			||||||
        </router-link>
 | 
					
 | 
				
			||||||
 | 
					            <img :src="video.uploaderAvatar" loading="lazy" />
 | 
				
			||||||
 | 
					            <router-link class="uk-text-bold" v-bind:to="video.uploaderUrl || '/'">
 | 
				
			||||||
 | 
					                <a>{{ video.uploader }}</a>
 | 
				
			||||||
 | 
					            </router-link>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <p class="uk-dark">
 | 
				
			||||||
 | 
					                <font-awesome-icon icon="thumbs-up"></font-awesome-icon>
 | 
				
			||||||
 | 
					                <b>{{ addCommas(video.likes) }}</b>
 | 
				
			||||||
 | 
					                 
 | 
				
			||||||
 | 
					                <font-awesome-icon icon="thumbs-down"></font-awesome-icon>
 | 
				
			||||||
 | 
					                <b>{{ addCommas(video.dislikes) }}</b>
 | 
				
			||||||
 | 
					            </p>
 | 
				
			||||||
 | 
					            <p>
 | 
				
			||||||
 | 
					                <font-awesome-icon icon="eye"></font-awesome-icon>
 | 
				
			||||||
 | 
					                <b>{{ addCommas(video.views) }}</b> views
 | 
				
			||||||
 | 
					            </p>
 | 
				
			||||||
 | 
					            <p>
 | 
				
			||||||
 | 
					                Uploaded on <b>{{ video.uploadDate }}</b>
 | 
				
			||||||
 | 
					            </p>
 | 
				
			||||||
 | 
					            <a class="uk-button uk-button-small" style="background: #222" @click="showDesc = !showDesc">
 | 
				
			||||||
 | 
					                {{ showDesc ? "+" : "-" }}
 | 
				
			||||||
 | 
					            </a>
 | 
				
			||||||
 | 
					            <p v-show="showDesc" class="uk-light" v-html="video.description"></p>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <p class="uk-dark">
 | 
					 | 
				
			||||||
            <font-awesome-icon icon="thumbs-up"></font-awesome-icon>
 | 
					 | 
				
			||||||
            <b>{{ addCommas(video.likes) }}</b>
 | 
					 | 
				
			||||||
             
 | 
					 | 
				
			||||||
            <font-awesome-icon icon="thumbs-down"></font-awesome-icon>
 | 
					 | 
				
			||||||
            <b>{{ addCommas(video.dislikes) }}</b>
 | 
					 | 
				
			||||||
        </p>
 | 
					 | 
				
			||||||
        <p>
 | 
					 | 
				
			||||||
            <font-awesome-icon icon="eye"></font-awesome-icon>
 | 
					 | 
				
			||||||
            <b>{{ addCommas(video.views) }}</b> views
 | 
					 | 
				
			||||||
        </p>
 | 
					 | 
				
			||||||
        <p>
 | 
					 | 
				
			||||||
            Uploaded on <b>{{ video.uploadDate }}</b>
 | 
					 | 
				
			||||||
        </p>
 | 
					 | 
				
			||||||
        <a class="uk-button uk-button-small" style="background: #222" @click="showDesc = !showDesc">
 | 
					 | 
				
			||||||
            {{ showDesc ? "+" : "-" }}
 | 
					 | 
				
			||||||
        </a>
 | 
					 | 
				
			||||||
        <p v-show="showDesc" class="uk-light" v-html="video.description"></p>
 | 
					 | 
				
			||||||
        <a v-if="sponsors && sponsors.segments">Sponsors Segments: {{ sponsors.segments.length }}</a>
 | 
					        <a v-if="sponsors && sponsors.segments">Sponsors Segments: {{ sponsors.segments.length }}</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <hr />
 | 
					        <hr />
 | 
				
			||||||
| 
						 | 
					@ -100,6 +105,7 @@
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import Constants from "@/Constants.js";
 | 
					import Constants from "@/Constants.js";
 | 
				
			||||||
import Player from "@/components/Player.vue";
 | 
					import Player from "@/components/Player.vue";
 | 
				
			||||||
 | 
					import ErrorHandler from "@/components/ErrorHandler.vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    name: "App",
 | 
					    name: "App",
 | 
				
			||||||
| 
						 | 
					@ -160,14 +166,16 @@ export default {
 | 
				
			||||||
                    this.video = data;
 | 
					                    this.video = data;
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                .then(() => {
 | 
					                .then(() => {
 | 
				
			||||||
                    document.title = this.video.title + " - Piped";
 | 
					                    if (!this.video.error) {
 | 
				
			||||||
 | 
					                        document.title = this.video.title + " - Piped";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    this.video.description = this.video.description
 | 
					                        this.video.description = this.video.description
 | 
				
			||||||
                        .replaceAll("http://www.youtube.com", "")
 | 
					                            .replaceAll("http://www.youtube.com", "")
 | 
				
			||||||
                        .replaceAll("https://www.youtube.com", "")
 | 
					                            .replaceAll("https://www.youtube.com", "")
 | 
				
			||||||
                        .replaceAll("\n", "<br>");
 | 
					                            .replaceAll("\n", "<br>");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    this.$refs.videoPlayer.loadVideo();
 | 
					                        this.$refs.videoPlayer.loadVideo();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        async getSponsors() {
 | 
					        async getSponsors() {
 | 
				
			||||||
| 
						 | 
					@ -197,6 +205,7 @@ export default {
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    components: {
 | 
					    components: {
 | 
				
			||||||
        Player,
 | 
					        Player,
 | 
				
			||||||
 | 
					        ErrorHandler,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue