Skip to content

Commit

Permalink
fix: unmatched pending requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkpunkd committed Nov 21, 2019
1 parent 08fc874 commit 7c5f747
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/peptalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class PepTalk extends EventEmitter implements PepTalkClient, PepTalkJS {
try {
this.emit('error', new UnspecifiedError(c, `Unmatched response for request ${c}.`))
} catch (err) { /* Allow emit with no listeners. */ }
return // everything beyond here needs pending to be set
}
if (m.slice(firstSpace + 1).startsWith('ok')) {
let response: PepResponse = {
Expand Down Expand Up @@ -463,7 +464,7 @@ class PepTalk extends EventEmitter implements PepTalkClient, PepTalkJS {
let errorIndex = m.indexOf('error')
let error: PepError
if (errorIndex < 0 || errorIndex > 10) {
error = new UnspecifiedError(c, `Error message with unexpected format: '${m}'`, pending.sent ? pending.sent : 'sent is undefined')
error = new UnspecifiedError(c, `Error message with unexpected format: '${m}'`, pending && pending.sent ? pending.sent : 'sent is undefined')
} else {
let endOfErrorName = m.slice(errorIndex + 6).indexOf(' ') + errorIndex + 6
endOfErrorName = endOfErrorName > errorIndex + 6 ? endOfErrorName : m.length
Expand Down

0 comments on commit 7c5f747

Please sign in to comment.