Mercurial > wikked
changeset 148:f02e049d6546
Vaguely better error reporting for when editing a page fails.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 11 Dec 2013 21:51:51 -0800 |
parents | d7890b46358e |
children | d29e2f337b00 |
files | static/js/wikked/models.js static/tpl/edit-page.html wikked/scm/base.py wikked/scm/mercurial.py wikked/web.py |
diffstat | 5 files changed, 35 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/static/js/wikked/models.js Wed Dec 11 21:51:26 2013 -0800 +++ b/static/js/wikked/models.js Wed Dec 11 21:51:51 2013 -0800 @@ -39,11 +39,11 @@ this._isSearching = true; var $model = this; $.getJSON('/api/search', { q: query }) - .success(function (data) { + .done(function (data) { $model._isSearching = false; callback(data); }) - .error(function() { + .fail(function() { $model._isSearching = false; }); }, @@ -104,10 +104,10 @@ doLogin: function(form) { var $model = this; $.post('/api/user/login', $(form).serialize()) - .success(function() { + .done(function() { $model.navigate('/', { trigger: true }); }) - .error(function() { + .fail(function() { $model.set('has_error', true); }); } @@ -259,12 +259,13 @@ urlRoot: '/api/edit/', doEdit: function(form) { var $model = this; - $.post(this.url(), $(form).serialize()) - .success(function(data) { + $.post(this.url(), $(form).serialize(), null, 'json') + .done(function(data) { $model._onEditSuccess(); }) - .error(function() { - alert('Error saving page...'); + .fail(function(jqxhr) { + var err = $.parseJSON(jqxhr.responseText); + $model.set('error', err.error); }); }, _onChangePath: function(path) {
--- a/static/tpl/edit-page.html Wed Dec 11 21:51:26 2013 -0800 +++ b/static/tpl/edit-page.html Wed Dec 11 21:51:51 2013 -0800 @@ -12,6 +12,11 @@ </ul> </div> </section> + {{#if error}} + <section class="alert alert-danger"> + <p><strong>Error:</strong> {{error.message}}</p> + </section> + {{/if}} <section id="wmd-input-wrapper"> <textarea id="wmd-input" name="text" placeholder="Your page's contents go here...">{{content}}</textarea> <div id="wmd-input-grip"></div>
--- a/wikked/scm/base.py Wed Dec 11 21:51:26 2013 -0800 +++ b/wikked/scm/base.py Wed Dec 11 21:51:51 2013 -0800 @@ -57,3 +57,15 @@ return self.rev_id != -1 +class SourceControlError(Exception): + def __init__(self, operation, message, command, output, *args): + Exception.__init__(self, *args) + self.operation = operation + self.message = message + self.command = command + self.output = output + + def __str__(self): + return "Error running '%s': %s\nCommand: %s\nOutput: %s" % ( + self.operation, self.message, self.command, self.output) +
--- a/wikked/scm/mercurial.py Wed Dec 11 21:51:26 2013 -0800 +++ b/wikked/scm/mercurial.py Wed Dec 11 21:51:51 2013 -0800 @@ -8,7 +8,7 @@ from hglib.error import CommandError from hglib.util import cmdbuilder from base import ( - SourceControl, Revision, + SourceControl, Revision, SourceControlError, ACTION_ADD, ACTION_EDIT, ACTION_DELETE, STATE_NEW, STATE_MODIFIED, STATE_COMMITTED) @@ -246,9 +246,7 @@ **kwargs) self.client.rawcommand(args) except CommandError as e: - logger.error("Failed running command '%s', got code '%s' and message '%s'. Output: %s" % ( - e.args, e.ret, e.err, e.out)) - raise + raise SourceControlError('commit', e.out, e.args, e.out) def revert(self, paths=None): if paths is not None:
--- a/wikked/web.py Wed Dec 11 21:51:26 2013 -0800 +++ b/wikked/web.py Wed Dec 11 21:51:51 2013 -0800 @@ -126,5 +126,11 @@ # Import the views. # (this creates a PyLint warning but it's OK) -import views +# pylint: disable=unused-import +import views.error +import views.read +import views.edit +import views.history +import views.special +import views.admin