Skip to content

Commit

Permalink
Fix ws safety marker
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Feb 14, 2024
1 parent c883255 commit 2904349
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export default function ey({
}

function close(fn, ws, code, data) {
ws[$.ws].open = false
fn(ws[$.ws], code, new Message(data, true))
ws.open = false
}

function open(fn, ws) {
Expand All @@ -184,14 +184,16 @@ export default function ey({
fn(ws[$.ws], new Message(data, binary))
}

function catcher(name, handlers, fn = (fn, ws, ...xs) => fn(ws[$.ws], ...xs)) {
if (!(name in handlers))
function catcher(name, handlers, fn) {
if (!(name in handlers) && !fn)
return

const method = handlers[name]
return function(ws, ...xs) {
try {
fn(method, ws, ...xs)
fn
? fn(method, ws, ...xs)
: method(ws[$.ws], ...xs)
} catch (error) {
name === 'close' || ws.end(1011, 'Internal Server Error')
console.error(500, 'Uncaught ' + name + ' error', error) // eslint-disable-line
Expand Down

0 comments on commit 2904349

Please sign in to comment.