Add exception handler for entire API.

This commit is contained in:
root 2014-10-20 17:39:41 -04:00
parent d1d4eac986
commit 8728f62478
2 changed files with 11 additions and 12 deletions

View File

@ -16,15 +16,15 @@ $jsonResponse = new JsonResponse();
require_once('helpers.php'); // Must come after $jsonResponse exists.
// Catch Exception if connection to DB failed
try {
R::setup('sqlite:taskboard.db');
createInitialUser();
} catch(Exception $e) {
$app->response->setStatus(503);
$jsonResponse->message = 'Connection to database failed. Ensure api is writable.';
function exceptionHandler($exception) {
header('Content-Type: application/json');
http_response_code(503);
echo '{"message": "API Error."}';
};
set_exception_handler('exceptionHandler');
$app->response->setBody($jsonResponse->asJson());
}
R::setup('sqlite:taskboard.db');
createInitialUser();
$app->notFound(function() use ($app, $jsonResponse) {
$app->response->setStatus(404);

View File

@ -28,10 +28,9 @@ function ($rootScope, $scope, $location, $window, UserService, AuthenticationSer
$location.path('/boards');
}).error(function(data, status) {
$scope.isSaving = false;
if (status === 401) {
$scope.errors.push(data.message);
} else {
$scope.errors.push('Something went wrong. Please try again.');
$scope.errors.push(data.message);
if (status === 503) {
$scope.errors[0] = $scope.errors[0] + ' Ensure api directory is writable.';
}
});
};