From 903edcbe542d89df854d9ea2731b1295bb086bbf Mon Sep 17 00:00:00 2001 From: Sandro Munda Date: Thu, 11 Oct 2018 14:31:29 +0200 Subject: [PATCH] Error handling - Catch properly the error when DATABASE_URL does not exist. --- CHANGELOG.md | 2 ++ templates/app/models/index.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3d919af..c8115704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +### Changed +- Error handling - Catch properly the error when DATABASE_URL does not exist. ## Release 1.11.1 ### Changed diff --git a/templates/app/models/index.js b/templates/app/models/index.js index 281a3b44..6bf140fb 100644 --- a/templates/app/models/index.js +++ b/templates/app/models/index.js @@ -2,6 +2,11 @@ const fs = require('fs'); const path = require('path'); const Sequelize = require('sequelize'); +if (!process.env.DATABASE_URL) { + console.error('Cannot connect to the database. Please declare the DATABASE_URL environment variable with the correct database connection string.'); + process.exit(); +} + let databaseOptions = { logging: process.env.NODE_ENV === 'development' ? console.log : false, pool: { maxConnections: 10, minConnections: 1 },