Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Dev tools ] Removed unused deps. Better error handling #760

Merged
merged 2 commits into from
Aug 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions public/controllers/dev-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
* Find more information about this on the LICENSE file.
*/
import { uiModules } from 'ui/modules'
import beautifier from '../utils/json-beautifier'
import CodeMirror from '../utils/codemirror/lib/codemirror'
import jsonLint from '../utils/codemirror/json-lint'
import queryString from 'query-string'
import $ from 'jquery'

const app = uiModules.get('app/wazuh', []);

// Logs controller
app.controller('devToolsController', function($scope, $rootScope, errorHandler, apiReq, $window, appState) {
app.controller('devToolsController', function($scope, apiReq, $window, appState, errorHandler, $document) {
let groups = [];

const apiInputBox = CodeMirror.fromTextArea(document.getElementById('api_input'),{
const apiInputBox = CodeMirror.fromTextArea($document[0].getElementById('api_input'),{
lineNumbers : true,
matchBrackets : true,
mode : { name: "javascript", json: true },
Expand Down Expand Up @@ -136,14 +136,14 @@ app.controller('devToolsController', function($scope, $rootScope, errorHandler,
jsonLint.parse(item.requestTextJson)
} catch(error) {
affectedGroups.push(item.requestText);
const msg = document.createElement("div");
const msg = $document[0].createElement("div");
msg.id = new Date().getTime()/1000;
const icon = msg.appendChild(document.createElement("div"));
const icon = msg.appendChild($document[0].createElement("div"));

icon.className = "lint-error-icon";
icon.id = new Date().getTime()/1000;
icon.onmouseover = () => {
const advice = msg.appendChild(document.createElement("span"));
const advice = msg.appendChild($document[0].createElement("span"));
advice.id = new Date().getTime()/1000;
advice.innerText = error.message || 'Error parsing query'
advice.className = 'lint-block-wz'
Expand Down Expand Up @@ -181,7 +181,7 @@ app.controller('devToolsController', function($scope, $rootScope, errorHandler,
highlightGroup(currentGroup);
}

const apiOutputBox = CodeMirror.fromTextArea(document.getElementById('api_output'),{
const apiOutputBox = CodeMirror.fromTextArea($document[0].getElementById('api_output'),{
lineNumbers : true,
matchBrackets : true,
mode : { name: "javascript", json: true },
Expand Down Expand Up @@ -279,9 +279,14 @@ app.controller('devToolsController', function($scope, $rootScope, errorHandler,
)

} catch(error) {
error && error.data ?
apiOutputBox.setValue(JSON.stringify(error.data)) :
apiOutputBox.setValue('Empty')
const parsedError = errorHandler.handle(error,null,null,true);
if(typeof parsedError === 'string') {
return apiOutputBox.setValue(parsedError);
} else if(error && error.data && typeof error.data === 'object') {
return apiOutputBox.setValue(JSON.stringify(error.data))
} else {
return apiOutputBox.setValue('Empty')
}
}

}
Expand Down