From a5f0f508eaf5d25cbcec504883696479a312e9ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Torkel=20=C3=96degaard?= <torkel@grafana.org>
Date: Tue, 16 Aug 2016 22:31:26 +0200
Subject: [PATCH] feat(inspector): fixed error handling, showing response body
 when data proxy returns text/html body

---
 public/app/core/controllers/inspect_ctrl.js | 8 ++++++--
 public/app/core/services/backend_srv.ts     | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/public/app/core/controllers/inspect_ctrl.js b/public/app/core/controllers/inspect_ctrl.js
index 2adc62f0039..0f8582ef5ce 100644
--- a/public/app/core/controllers/inspect_ctrl.js
+++ b/public/app/core/controllers/inspect_ctrl.js
@@ -7,7 +7,7 @@ define([
 function (angular, _, $, coreModule) {
   'use strict';
 
-  coreModule.default.controller('InspectCtrl', function($scope) {
+  coreModule.default.controller('InspectCtrl', function($scope, $sanitize) {
     var model = $scope.inspector;
 
     function getParametersFromQueryString(queryString) {
@@ -32,7 +32,11 @@ function (angular, _, $, coreModule) {
       if (_.isString(model.error.data)) {
         $scope.response = $("<div>" + model.error.data + "</div>").text();
       } else if (model.error.data) {
-        $scope.response = angular.toJson(model.error.data, true);
+        if (model.error.data.response) {
+          $scope.response = $sanitize(model.error.data.response);
+        } else {
+          $scope.response = angular.toJson(model.error.data, true);
+        }
       } else if (model.error.message) {
         $scope.message = model.error.message;
       }
diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts
index 17299f452a3..fdc2b6cb974 100644
--- a/public/app/core/services/backend_srv.ts
+++ b/public/app/core/services/backend_srv.ts
@@ -138,7 +138,8 @@ export class BackendSrv {
       //populate error obj on Internal Error
       if (_.isString(err.data) && err.status === 500) {
         err.data = {
-          error: err.statusText
+          error: err.statusText,
+          response: err.data,
         };
       }