2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import coreModule from '../core_module';
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2017-10-26 06:27:17 -05:00
|
|
|
export class InspectCtrl {
|
|
|
|
/** @ngInject */
|
|
|
|
constructor($scope, $sanitize) {
|
2018-08-26 14:52:57 -05:00
|
|
|
const model = $scope.inspector;
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
$scope.init = function() {
|
2014-04-05 09:04:26 -05:00
|
|
|
$scope.editor = { index: 0 };
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
if (!model.error) {
|
2014-04-05 09:04:26 -05:00
|
|
|
return;
|
2014-04-05 06:26:48 -05:00
|
|
|
}
|
|
|
|
|
2014-08-11 05:11:24 -05:00
|
|
|
if (_.isString(model.error.data)) {
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.response = $('<div>' + model.error.data + '</div>').text();
|
2015-09-02 03:35:15 -05:00
|
|
|
} else if (model.error.data) {
|
2016-08-16 15:31:26 -05:00
|
|
|
if (model.error.data.response) {
|
|
|
|
$scope.response = $sanitize(model.error.data.response);
|
|
|
|
} else {
|
|
|
|
$scope.response = angular.toJson(model.error.data, true);
|
|
|
|
}
|
2015-09-02 03:35:15 -05:00
|
|
|
} else if (model.error.message) {
|
|
|
|
$scope.message = model.error.message;
|
2014-08-11 05:11:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (model.error.config && model.error.config.params) {
|
2018-09-04 07:27:03 -05:00
|
|
|
$scope.request_parameters = _.map(model.error.config.params, (value, key) => {
|
2017-12-19 09:06:54 -06:00
|
|
|
return { key: key, value: value };
|
2014-08-11 05:11:24 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-05 09:04:26 -05:00
|
|
|
if (model.error.stack) {
|
2016-12-16 09:08:32 -06:00
|
|
|
$scope.editor.index = 3;
|
2014-04-05 09:04:26 -05:00
|
|
|
$scope.stack_trace = model.error.stack;
|
|
|
|
$scope.message = model.error.message;
|
|
|
|
}
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2015-09-02 03:35:15 -05:00
|
|
|
if (model.error.config && model.error.config.data) {
|
2016-12-16 09:08:32 -06:00
|
|
|
$scope.editor.index = 2;
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2015-09-02 03:35:15 -05:00
|
|
|
if (_.isString(model.error.config.data)) {
|
2017-12-21 01:39:31 -06:00
|
|
|
$scope.request_parameters = this.getParametersFromQueryString(model.error.config.data);
|
2017-12-19 09:06:54 -06:00
|
|
|
} else {
|
2018-09-04 07:27:03 -05:00
|
|
|
$scope.request_parameters = _.map(model.error.config.data, (value, key) => {
|
2017-12-19 09:06:54 -06:00
|
|
|
return { key: key, value: angular.toJson(value, true) };
|
2015-09-02 03:35:15 -05:00
|
|
|
});
|
2014-04-05 06:26:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-10-26 06:27:17 -05:00
|
|
|
}
|
|
|
|
getParametersFromQueryString(queryString) {
|
2018-08-26 14:52:57 -05:00
|
|
|
const result = [];
|
|
|
|
const parameters = queryString.split('&');
|
|
|
|
for (let i = 0; i < parameters.length; i++) {
|
|
|
|
const keyValue = parameters[i].split('=');
|
2017-10-26 06:27:17 -05:00
|
|
|
if (keyValue[1].length > 0) {
|
2017-12-19 09:06:54 -06:00
|
|
|
result.push({
|
|
|
|
key: keyValue[0],
|
2018-09-03 04:30:44 -05:00
|
|
|
value: (window as any).unescape(keyValue[1]),
|
2017-12-19 09:06:54 -06:00
|
|
|
});
|
2017-10-26 06:27:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('InspectCtrl', InspectCtrl);
|