Skip to content

Commit

Permalink
feat: add error event
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Van Camp committed Aug 29, 2019
1 parent ad4fdc7 commit a86d925
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ bingosync.on("board-changed", boardState => {
});
});

// Set up an error handler to be informed of runtime issues.
// If you don't attach this handler, errors will be silently discarded.
bingosync.on("error", error => {
console.error("something went wrong:", error);
});

// Connect to the room.
bingosync
.joinRoom({
Expand Down
9 changes: 4 additions & 5 deletions src/lib/bingosync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const debug = dbg("bingosync-api");
interface Events {
"status-changed": [string];
"board-changed": [BoardState];
error: [Error];
}

export type CellColor =
Expand Down Expand Up @@ -323,12 +324,10 @@ export class Bingosync extends EventEmitter<Events> {
"Socket protocol error:",
json.error ? json.error : json,
);
const errorMsg = json.error ? json.error : "unknown error";
this.emit("error", new Error(errorMsg));
if (!settled) {
reject(
new Error(
json.error ? json.error : "unknown error",
),
);
reject(new Error(errorMsg));
settled = true;
}

Expand Down

0 comments on commit a86d925

Please # to comment.