Skip to content

Commit

Permalink
Return json error message on missing config
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Nov 4, 2018
1 parent 9ce482e commit fbc3940
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/bootstrap.php
Expand Up @@ -24,6 +24,19 @@

use Volkszaehler\Util;

function fail($msg) {
if (preg_match('/\.json/', $_SERVER['REQUEST_URI'])) {
header('Content-type: application/json');
echo json_encode([
'version' => VZ_VERSION,
'exception' => array(
'message' => $msg
)
]);
}
die();
}

// enable strict error reporting
error_reporting(E_ALL | E_STRICT);

Expand All @@ -36,11 +49,11 @@
}

if (!file_exists(VZ_DIR . '/vendor/autoload.php')) {
die('Could not find autoloader. Check that dependencies have been installed via `composer install`.');
fail('Could not find autoloader. Check that dependencies have been installed via `composer install`.');
}

if (!file_exists(VZ_DIR . '/etc/volkszaehler.conf.php')) {
die('Could not find config file. Check that etc/volkszaehler.conf.php exists.');
fail('Could not find config file. Check that etc/volkszaehler.conf.php exists.');
}

require_once VZ_DIR . '/vendor/autoload.php';
Expand Down

0 comments on commit fbc3940

Please sign in to comment.