Skip to content
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
18 changes: 12 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ function parseSearchQuery(code: string): ElasticSearchQuery | null {
let body: Object;

if (jsonBodyStart > -1) {
try {
body = JSON.parse(code.substring(jsonBodyStart));
} catch (e) {
body = null
}
body = code.substring(jsonBodyStart);
}

return <ElasticSearchQuery>{ method, path, body };
Expand Down Expand Up @@ -99,7 +95,7 @@ async function executeQuery(code:string, context: vscode.ExtensionContext, resul
request(<request.UrlOptions & request.CoreOptions>{
url: requestUrl,
method: query.method,
json: query.body
body: query.body
}, (error, response, body) => {
sbi.dispose();
const endTime = new Date().getTime();
Expand All @@ -117,6 +113,16 @@ async function executeQuery(code:string, context: vscode.ExtensionContext, resul
} else {
results = body;
}

if (response.statusCode == 400) {
const matched = results.toString().match(/"line":\s*([0-9]+),/);
if (matched != null) {
const startLineIndex = code.split('\n').findIndex((line: string) => { return line.indexOf('{') > -1 });
const actualLineNumber = Number(matched[1]) + startLineIndex
results = results.toString().replace(RegExp('"line": ' + matched[1] + ',', 'g'), '"line": ' + actualLineNumber + ',')
}
}

results = `[Query Information]

Requested Time ${new Date(endTime).toLocaleString()}
Expand Down