Browse Source

ts: Fix uncaught base64 log error (#423)

aac 4 years ago
parent
commit
e5b3f0aa06
1 changed files with 7 additions and 1 deletions
  1. 7 1
      ts/src/coder/event.ts

+ 7 - 1
ts/src/coder/event.ts

@@ -47,7 +47,13 @@ export class EventCoder {
   }
 
   public decode(log: string): Event | null {
-    const logArr = Buffer.from(base64.toByteArray(log));
+    let logArr: Buffer;
+    // This will throw if log length is not a multiple of 4.
+    try {
+      logArr = Buffer.from(base64.toByteArray(log));
+    } catch (e){
+      return null;
+    }
     const disc = base64.fromByteArray(logArr.slice(0, 8));
 
     // Only deserialize if the discriminator implies a proper event.