Skip to content

Commit

Permalink
Only return unique completions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Jan 15, 2020
1 parent 0b22322 commit 379af85
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/http-console.js
Expand Up @@ -63,11 +63,11 @@ class HTTPConsole {
}

completer (partial, cb) {
let completions = [], finished = 0
let completions = new Set(), finished = 0

const addCompletions = (err, newCompletions) => {
if (!err) completions.push(...newCompletions)
if (++finished === this.completers.length) cb(null, [completions, partial])
if (!err) newCompletions.forEach(c => completions.add(c))
if (++finished === this.completers.length) cb(null, [[...completions], partial])
}

// Node seems to just *exit* when we don't return from this callback. Doing
Expand Down Expand Up @@ -168,10 +168,15 @@ class HTTPConsole {

if (this.json) options.responseType = 'json'

// We're using a prefixed got, so trim the first slash if we have it.
const resp = await this.got(url[0] === '/' ? url.slice(1) : url, options)
this.renderHeaders(resp)
cb(null, resp.body)
try {
// We're using a prefixed got, so trim the first slash if we have it.
const resp = await this.got(url[0] === '/' ? url.slice(1) : url, options)
this.renderHeaders(resp)
cb(null, resp.body)
}
catch (e) {
this.output.write(this._stylize(`Error: ${e.message}\n`, 'red'))
}
}
}

Expand Down

0 comments on commit 379af85

Please sign in to comment.