Skip to content

Commit

Permalink
fixing error if message is already served or not matched
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Feb 27, 2025
1 parent 286bf01 commit 92d8ba6
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/drivers/iframe-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { SqliteLikeBaseDriver } from "./sqlite-base-driver";

type ParentResponseData =
| {
type: "query";
id: number;
data: DatabaseResultSet;
error?: string;
}
type: "query";
id: number;
data: DatabaseResultSet;
error?: string;
}
| {
type: "transaction";
id: number;
data: DatabaseResultSet[];
error?: string;
};
type: "transaction";
id: number;
data: DatabaseResultSet[];
error?: string;
};

type PromiseResolveReject = {
resolve: (value: any) => void;
Expand All @@ -29,6 +29,10 @@ class IframeConnection {

listen() {
const handler = (e: MessageEvent<ParentResponseData>) => {
// Make no sense to handle message with no matching id
// This throw a lot of error in console for some reason
if (!this.queryPromise[e.data.id]) return;

if (e.data.error) {
this.queryPromise[e.data.id].reject(e.data.error);
delete this.queryPromise[e.data.id];
Expand Down Expand Up @@ -124,7 +128,7 @@ export class IframeSQLiteDriver extends SqliteLikeBaseDriver {
this.conn.listen();
}

close(): void {}
close(): void { }

async query(stmt: string): Promise<DatabaseResultSet> {
const r = await this.conn.query(stmt);
Expand All @@ -147,7 +151,7 @@ export class IframeMySQLDriver extends MySQLLikeDriver {
this.conn.listen();
}

close(): void {}
close(): void { }

async query(stmt: string): Promise<DatabaseResultSet> {
const r = await this.conn.query(stmt);
Expand Down Expand Up @@ -179,7 +183,7 @@ export class IframePostgresDriver extends PostgresLikeDriver {
this.conn.listen();
}

close(): void {}
close(): void { }

async query(stmt: string): Promise<DatabaseResultSet> {
const r = await this.conn.query(stmt);
Expand Down

0 comments on commit 92d8ba6

Please sign in to comment.