Skip to content

Commit

Permalink
Add error message when there are no videos
Browse files Browse the repository at this point in the history
  • Loading branch information
alaindet committed Apr 30, 2021
1 parent eaa8b25 commit 841f003
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [1.3.1] - 2021-04-30

### Added
- Error when starting app with no videos

## [1.3.0] - 2021-02-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "offline-video-player",
"version": "1.0.0",
"version": "1.3.1",
"description": "A simple offline video player",
"main": "src/index.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const lastWatchedVideo = require('../services/last-watched-video.service');

const getHome = (req, res) => {
const videos = videosCache.get('videos');

if (!videos[0]) {
const title = 'No videos found';
const message = 'No videos found. Please provide .mp4 videos in the /videos folder or set the videos folder via --videos-path option. See <a href="https://github.com/alaindet/offline-video-player">offline-video-player repository on GitHub</a> for more information.';
console.error('ERROR', message);
return res.status(404).render('pages/404', { title, message });
}

res.render('pages/home', {
pageTitle: 'Offline Video Player',
firstVideo: videos[0].urlPath,
Expand Down
1 change: 1 addition & 0 deletions src/controllers/video.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const getVideo = (req, res) => {
res.render('pages/video', data);
} catch (error) {
console.error('ERROR', error);
const title = 'No video found';
const message = error.message;
return res.status(404).render('pages/404', { message });
}
Expand Down
5 changes: 3 additions & 2 deletions src/views/pages/404.ejs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<%#
# Variables
- title
- message
#%>
<%- include('../includes/top.ejs') %>

<h1>Page not found</h1>
<p><%= message %></p>
<h1><%= title %></h1>
<p><%- message %></p>

<%- include('../includes/bottom.ejs') %>

0 comments on commit 841f003

Please sign in to comment.