mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
Return a 400 and error message instead of 500ing on a personal to an invalid user.
(imported from commit b8cdf342f2919aa0dbd2e30764c7662b6756aa57)
This commit is contained in:
@@ -48,6 +48,7 @@ $(function() {
|
||||
var buttons = $('#class-message, #personal-message').find('input[type="submit"]');
|
||||
|
||||
var options = {
|
||||
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
||||
beforeSubmit: function (form, _options) {
|
||||
send_status.removeClass(status_classes)
|
||||
.addClass('alert-info')
|
||||
@@ -64,10 +65,16 @@ $(function() {
|
||||
.stop(true).fadeTo(0,1).delay(1000).fadeOut(1000);
|
||||
buttons.removeAttr('disabled');
|
||||
},
|
||||
error: function() {
|
||||
error: function(xhr) {
|
||||
var response = "Error sending message";
|
||||
if (xhr.status.toString().charAt(0) == "4") {
|
||||
// Only display the error response for 4XX, where we've crafted
|
||||
// a nice response.
|
||||
response += ": " + $.parseJSON(xhr.responseText).msg;
|
||||
}
|
||||
send_status.removeClass(status_classes)
|
||||
.addClass('alert-error')
|
||||
.text('Error sending message ')
|
||||
.text(response)
|
||||
.append($('<span />')
|
||||
.addClass('send-status-close').html('×')
|
||||
.click(function () { send_status.stop(true).fadeOut(500); }))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render
|
||||
@@ -146,8 +146,12 @@ def zephyr(request):
|
||||
recipient = Recipient.objects.get(type_id=huddle.pk, type="huddle")
|
||||
else:
|
||||
# This is actually a personal message
|
||||
if User.objects.filter(username=recipient_data):
|
||||
recipient_user = User.objects.get(username=recipient_data)
|
||||
if not User.objects.filter(username=recipient_data):
|
||||
return HttpResponseBadRequest(
|
||||
simplejson.dumps({"result":"error", "msg":"Invalid username"}),
|
||||
content_type="application/json")
|
||||
|
||||
recipient_user = User.objects.get(username=recipient_data)
|
||||
recipient_user_profile = UserProfile.objects.get(user=recipient_user)
|
||||
recipient = Recipient.objects.get(type_id=recipient_user_profile.id, type="personal")
|
||||
else:
|
||||
|
Reference in New Issue
Block a user