FIX: show error msg on grant badge if message available from backend (#6801)

FIX: show error msg on grant badge if message available from backend (#6801)

diff --git a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
index c71c83c..06cec9f 100644
--- a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6
@@ -1,4 +1,5 @@
 import GrantBadgeController from "discourse/mixins/grant-badge-controller";
+import { popupAjaxError } from "discourse/lib/ajax-error";
 
 export default Ember.Controller.extend(GrantBadgeController, {
   adminUser: Ember.inject.controller(),
@@ -70,9 +71,8 @@ export default Ember.Controller.extend(GrantBadgeController, {
             }
           });
         },
-        function() {
-          // Failure
-          bootbox.alert(I18n.t("generic_error"));
+        function(error) {
+          popupAjaxError(error);
         }
       );
     },
diff --git a/app/controllers/user_badges_controller.rb b/app/controllers/user_badges_controller.rb
index b3852a6..cb67ee7 100644
--- a/app/controllers/user_badges_controller.rb
+++ b/app/controllers/user_badges_controller.rb
@@ -58,7 +58,7 @@ class UserBadgesController < ApplicationController
 
     if params[:reason].present?
       unless is_badge_reason_valid? params[:reason]
-        return render json: { failed: I18n.t('invalid_grant_badge_reason_link') }, status: 400
+        return render json: failed_json.merge(message: I18n.t('invalid_grant_badge_reason_link')), status: 400
       end
 
       path = begin

GitHub
sha: 0fca3205