diff --git a/pillar/web/users/routes.py b/pillar/web/users/routes.py index ded7a0c7..30950325 100644 --- a/pillar/web/users/routes.py +++ b/pillar/web/users/routes.py @@ -6,6 +6,8 @@ from flask import (abort, Blueprint, current_app, flash, redirect, render_template, request, session, url_for) from flask_login import login_required, login_user, logout_user, current_user from flask_oauthlib.client import OAuthException +from werkzeug import exceptions as wz_exceptions + from pillar.auth import UserClass, subscriptions from pillar.web import system_util from .forms import UserProfileForm @@ -192,7 +194,13 @@ def users_edit(user_id): if not current_user.has_role('admin'): return abort(403) api = system_util.pillar_api() - user = User.find(user_id, api=api) + + try: + user = User.find(user_id, api=api) + except sdk_exceptions.ResourceNotFound: + log.warning('Non-existing user %r requested.', user_id) + raise wz_exceptions.NotFound('Non-existing user %r requested.' % user_id) + form = UserEditForm() if form.validate_on_submit(): def get_groups(roles): diff --git a/src/templates/users/index.jade b/src/templates/users/index.jade index 317eb8bd..a589b64e 100644 --- a/src/templates/users/index.jade +++ b/src/templates/users/index.jade @@ -104,7 +104,20 @@ script(type="text/javascript"). var url = '/u/' + userId + '/edit?embed=1'; $.get(url, function(dataHtml){ $('#search-hit-container').html(dataHtml); - }); + }) + .fail(function(jqXHR, textStatus, errorThrown) { + var $userbox = $(".search-hit.users[data-user-id='" + userId + "']"); + var $msgbox = $userbox.find('.search-hit-roles'); + + if (console) console.log('Error fetching user', userId, '; jqXHR=', jqXHR); + $userbox.addClass('alert alert-warning'); + if (jqXHR.status == 404) { + $msgbox.text('This user does not seem to exist.'); + } else { + $msgbox.text('There was an error fetching the user: ' + jqXHR.responseText + '.') + } + }) + ; } $('body').on('click', '.search-hit', function(){