Added default error handler.

This commit is contained in:
Alexis Lahouze 2013-07-30 21:29:47 +02:00
parent 2a9f5b2500
commit 3ddd63701e
2 changed files with 30 additions and 4 deletions

View File

@ -20,7 +20,7 @@ from api.controller.entries import *
from api.controller.accounts import *
from api.controller.scheduled_operations import *
from flask import redirect, render_template
from flask import redirect, render_template, jsonify
@app.route('/')
def root():
@ -34,6 +34,11 @@ def index():
def scheduler():
return render_template('scheduler.html')
@app.errorhandler(BaseException)
def default_errorhandler(error):
print "An error occured: %s" % error
return jsonify(title="Error", text="Error %s" % str(error)), 500
if __name__ == '__main__':
app.run(debug=True)

View File

@ -114,9 +114,30 @@
{% block js %}{% endblock %}
<script type="text/javascript">
angular.module('$strap').config(function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
angular.module('$strap').config(function($interpolateProvider, $httpProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
$httpProvider.responseInterceptors.push(['$rootScope', '$q', function(scope, $q) {
function success(response) {
return response;
}
function error(response) {
$.pnotify({
type: "error",
title: response.data.title,
text: response.data.text,
width: 500px
})
return $q.reject(response);
}
return function(promise) {
return promise.then(success, error);
}
}]);
});
</script>
</body>